forked from travisjeffery/jocko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_groups_response.go
53 lines (48 loc) · 1.01 KB
/
list_groups_response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package protocol
type ListGroupsResponse struct {
ErrorCode int16
Groups map[string]string
}
func (r *ListGroupsResponse) Encode(e PacketEncoder) error {
e.PutInt16(r.ErrorCode)
if err := e.PutArrayLength(len(r.Groups)); err != nil {
return err
}
for groupID, protocolType := range r.Groups {
if err := e.PutString(groupID); err != nil {
return err
}
if err := e.PutString(protocolType); err != nil {
return err
}
}
return nil
}
func (r *ListGroupsResponse) Decode(d PacketDecoder) (err error) {
if r.ErrorCode, err = d.Int16(); err != nil {
return err
}
groupCount, err := d.ArrayLength()
if err != nil {
return err
}
r.Groups = make(map[string]string)
for i := 0; i < groupCount; i++ {
groupID, err := d.String()
if err != nil {
return err
}
protocolType, err := d.String()
if err != nil {
return err
}
r.Groups[groupID] = protocolType
}
return nil
}
func (r *ListGroupsResponse) Key() int16 {
return 16
}
func (r *ListGroupsResponse) Version() int16 {
return 0
}