graphvent/group.go

46 lines
900 B
Go

2023-07-20 22:08:28 -06:00
package graphvent
import (
"encoding/json"
)
2023-07-26 00:18:11 -06:00
type GroupExt struct {
Members map[NodeID]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) {
return json.Marshal(ext)
2023-07-25 09:51:55 -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
},
})
}
func NewGroupExt(members map[NodeID]string) *GroupExt {
2023-07-26 11:56:10 -06:00
if members == nil {
members = map[NodeID]string{}
2023-07-26 11:56:10 -06:00
}
2023-07-26 11:56:10 -06:00
return &GroupExt{
Members: members,
}
}
2023-08-01 20:55:15 -06:00
func (ext *GroupExt) Deserialize(ctx *Context, data []byte) error {
ext.Members = map[NodeID]string{}
return json.Unmarshal(data, ext)
2023-07-26 00:18:11 -06:00
}
2023-07-25 09:51:55 -06:00
func (ext *GroupExt) Process(ctx *Context, node *Node, source NodeID, signal Signal) Messages {
return nil
2023-07-26 00:18:11 -06:00
}