()
| 3 | import "github.com/zeppelinmc/zeppelin/protocol/net/packet/play" |
| 4 | |
| 5 | func (mgr *Manager) Encode() *play.Commands { |
| 6 | if mgr.graph != nil { |
| 7 | return mgr.graph |
| 8 | } |
| 9 | pk := play.Commands{ |
| 10 | Nodes: make([]play.Node, 1, len(mgr.commands)+1), |
| 11 | } |
| 12 | pk.Nodes[0] = play.Node{ |
| 13 | Children: make([]int32, 0, len(mgr.commands)), |
| 14 | } |
| 15 | |
| 16 | for _, cmd := range mgr.commands { |
| 17 | commandNodeIndex := int32(len(pk.Nodes)) |
| 18 | pk.Nodes[0].Children = append(pk.Nodes[0].Children, commandNodeIndex) |
| 19 | pk.Nodes = append(pk.Nodes, cmd.Node.Node) |
| 20 | |
| 21 | if cmd.Namespace != "" { |
| 22 | pk.Nodes[0].Children = append(pk.Nodes[0].Children, int32(len(pk.Nodes))) |
| 23 | pk.Nodes = append(pk.Nodes, play.Node{ |
| 24 | Flags: play.NodeLiteral | play.NodeRedirect, |
| 25 | Name: cmd.Namespace + ":" + cmd.Node.Name, |
| 26 | RedirectNode: commandNodeIndex, |
| 27 | }) |
| 28 | } |
| 29 | |
| 30 | for _, alias := range cmd.Aliases { |
| 31 | pk.Nodes[0].Children = append(pk.Nodes[0].Children, int32(len(pk.Nodes))) |
| 32 | pk.Nodes = append(pk.Nodes, play.Node{ |
| 33 | Flags: play.NodeLiteral | play.NodeRedirect, |
| 34 | Name: alias, |
| 35 | RedirectNode: commandNodeIndex, |
| 36 | }) |
| 37 | |
| 38 | if cmd.Namespace != "" { |
| 39 | pk.Nodes[0].Children = append(pk.Nodes[0].Children, int32(len(pk.Nodes))) |
| 40 | pk.Nodes = append(pk.Nodes, play.Node{ |
| 41 | Flags: play.NodeLiteral | play.NodeRedirect, |
| 42 | Name: cmd.Namespace + ":" + alias, |
| 43 | RedirectNode: commandNodeIndex, |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | for _, child := range cmd.Node.children { |
| 49 | appendNode(commandNodeIndex, child, &pk.Nodes) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return &pk |
| 54 | } |
| 55 | |
| 56 | func appendNode(parentIndex int32, n Node, tgt *[]play.Node) { |
| 57 | index := int32(len(*tgt)) |
nothing calls this directly
no test coverage detected