2023-07-20 22:08:28 -06:00
|
|
|
package graphvent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
2023-07-26 00:18:11 -06:00
|
|
|
type GroupExt struct {
|
2023-07-28 00:04:18 -06:00
|
|
|
Members map[NodeID]string
|
|
|
|
}
|
|
|
|
|
|
|
|
type GroupExtJSON struct {
|
|
|
|
Members map[string]string `json:"members"`
|
2023-07-25 09:51:55 -06:00
|
|
|
}
|
|
|
|
|
2023-07-26 00:18:11 -06:00
|
|
|
func (ext *GroupExt) Type() ExtType {
|
|
|
|
return GroupExtType
|
2023-07-25 09:51:55 -06:00
|
|
|
}
|
|
|
|
|
2023-07-26 00:18:11 -06:00
|
|
|
func (ext *GroupExt) Serialize() ([]byte, error) {
|
2023-07-28 00:04:18 -06:00
|
|
|
return json.MarshalIndent(&GroupExtJSON{
|
|
|
|
Members: IDMap(ext.Members),
|
2023-07-26 00:18:11 -06:00
|
|
|
}, "", " ")
|
2023-07-25 09:51:55 -06:00
|
|
|
}
|
|
|
|
|
2023-07-28 11:21:18 -06:00
|
|
|
func (ext *GroupExt) Field(name string) interface{} {
|
|
|
|
return ResolveFields(ext, name, map[string]func(*GroupExt)interface{}{
|
|
|
|
"members": func(ext *GroupExt) interface{} {
|
|
|
|
return ext.Members
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-28 00:04:18 -06:00
|
|
|
func NewGroupExt(members map[NodeID]string) *GroupExt {
|
2023-07-26 11:56:10 -06:00
|
|
|
if members == nil {
|
2023-07-28 00:04:18 -06:00
|
|
|
members = map[NodeID]string{}
|
2023-07-26 11:56:10 -06:00
|
|
|
}
|
2023-07-28 00:04:18 -06:00
|
|
|
|
2023-07-26 11:56:10 -06:00
|
|
|
return &GroupExt{
|
|
|
|
Members: members,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-26 00:18:11 -06:00
|
|
|
func LoadGroupExt(ctx *Context, data []byte) (Extension, error) {
|
2023-07-28 00:04:18 -06:00
|
|
|
var j GroupExtJSON
|
2023-07-26 00:18:11 -06:00
|
|
|
err := json.Unmarshal(data, &j)
|
2023-07-25 09:51:55 -06:00
|
|
|
|
2023-07-28 00:04:18 -06:00
|
|
|
members, err := LoadIDMap(j.Members)
|
2023-07-26 00:18:11 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-28 00:04:18 -06:00
|
|
|
return &GroupExt{
|
|
|
|
Members: members,
|
|
|
|
}, nil
|
2023-07-26 00:18:11 -06:00
|
|
|
}
|
2023-07-25 09:51:55 -06:00
|
|
|
|
2023-07-27 15:27:14 -06:00
|
|
|
func (ext *GroupExt) Process(ctx *Context, princ_id NodeID, node *Node, signal Signal) {
|
|
|
|
return
|
2023-07-26 00:18:11 -06:00
|
|
|
}
|
2023-07-28 00:04:18 -06:00
|
|
|
|