-
Notifications
You must be signed in to change notification settings - Fork 18
/
describe_groups_response.go
127 lines (102 loc) · 3.08 KB
/
describe_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package healer
import (
"encoding/binary"
"fmt"
)
type MemberDetail struct {
MemberID string
ClientID string
ClientHost string
MemberMetadata []byte
RawMemberAssignment []byte `json:"-"`
MemberAssignment *MemberAssignment
}
type GroupDetail struct {
ErrorCode int16
GroupID string
State string
ProtocolType string
Protocol string
Members []MemberDetail
}
type DescribeGroupsResponse struct {
CorrelationID uint32
Groups []*GroupDetail
}
func (r DescribeGroupsResponse) Error() error {
for _, group := range r.Groups {
if group.ErrorCode != 0 {
return KafkaError(group.ErrorCode)
}
}
return nil
}
func NewDescribeGroupsResponse(payload []byte) (r DescribeGroupsResponse, err error) {
var (
l int
offset int = 0
)
responseLength := int(binary.BigEndian.Uint32(payload))
if responseLength+4 != len(payload) {
return r, fmt.Errorf("describeGroups response length did not match: %d!=%d", responseLength+4, len(payload))
}
offset += 4
r.CorrelationID = uint32(binary.BigEndian.Uint32(payload[offset:]))
offset += 4
groupCount := uint32(binary.BigEndian.Uint32(payload[offset:]))
offset += 4
r.Groups = make([]*GroupDetail, groupCount)
for i := range r.Groups {
group := &GroupDetail{}
group.ErrorCode = int16(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
if err == nil && group.ErrorCode != 0 {
err = KafkaError(group.ErrorCode)
}
l = int(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
group.GroupID = string(payload[offset : offset+l])
offset += l
l = int(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
group.State = string(payload[offset : offset+l])
offset += l
l = int(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
group.ProtocolType = string(payload[offset : offset+l])
offset += l
l = int(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
group.Protocol = string(payload[offset : offset+l])
offset += l
memberCount := int(binary.BigEndian.Uint32(payload[offset:]))
offset += 4
group.Members = make([]MemberDetail, memberCount)
for i := range group.Members {
l = int(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
group.Members[i].MemberID = string(payload[offset : offset+l])
offset += l
l = int(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
group.Members[i].ClientID = string(payload[offset : offset+l])
offset += l
l = int(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
group.Members[i].ClientHost = string(payload[offset : offset+l])
offset += l
l = int(binary.BigEndian.Uint32(payload[offset:]))
offset += 4
copy(group.Members[i].MemberMetadata, payload[offset:offset+l])
offset += l
l = int(binary.BigEndian.Uint32(payload[offset:]))
offset += 4
group.Members[i].RawMemberAssignment = make([]byte, l)
copy(group.Members[i].RawMemberAssignment, payload[offset:offset+l])
group.Members[i].MemberAssignment, err = NewMemberAssignment(group.Members[i].RawMemberAssignment)
offset += l
}
r.Groups[i] = group
}
return r, err
}