1
1
package sarama
2
2
3
3
type DescribeGroupsResponse struct {
4
- Version int16
4
+ // Version defines the protocol version to use for encode and decode
5
+ Version int16
6
+ // ThrottleTimeMs contains the duration in milliseconds for which the
7
+ // request was throttled due to a quota violation, or zero if the request
8
+ // did not violate any quota.
5
9
ThrottleTimeMs int32
6
- Groups []* GroupDescription
10
+ // Groups contains each described group.
11
+ Groups []* GroupDescription
7
12
}
8
13
9
- func (r * DescribeGroupsResponse ) encode (pe packetEncoder ) error {
14
+ func (r * DescribeGroupsResponse ) encode (pe packetEncoder ) ( err error ) {
10
15
if r .Version >= 1 {
11
16
pe .putInt32 (r .ThrottleTimeMs )
12
17
}
13
18
if err := pe .putArrayLength (len (r .Groups )); err != nil {
14
19
return err
15
20
}
16
21
17
- for _ , groupDescription := range r .Groups {
18
- groupDescription .Version = r .Version
19
- if err := groupDescription .encode (pe ); err != nil {
22
+ for _ , block := range r .Groups {
23
+ if err := block .encode (pe , r .Version ); err != nil {
20
24
return err
21
25
}
22
26
}
@@ -31,17 +35,16 @@ func (r *DescribeGroupsResponse) decode(pd packetDecoder, version int16) (err er
31
35
return err
32
36
}
33
37
}
34
- n , err := pd .getArrayLength ()
35
- if err != nil {
38
+ if numGroups , err := pd .getArrayLength (); err != nil {
36
39
return err
37
- }
38
-
39
- r . Groups = make ([] * GroupDescription , n )
40
- for i := 0 ; i < n ; i ++ {
41
- r . Groups [ i ] = new ( GroupDescription )
42
- r . Groups [ i ]. Version = r . Version
43
- if err := r . Groups [ i ]. decode ( pd ); err != nil {
44
- return err
40
+ } else if numGroups > 0 {
41
+ r . Groups = make ([] * GroupDescription , numGroups )
42
+ for i := 0 ; i < numGroups ; i ++ {
43
+ block := & GroupDescription {}
44
+ if err := block . decode ( pd , r . Version ); err != nil {
45
+ return err
46
+ }
47
+ r . Groups [ i ] = block
45
48
}
46
49
}
47
50
@@ -68,20 +71,32 @@ func (r *DescribeGroupsResponse) requiredVersion() KafkaVersion {
68
71
return V0_9_0_0
69
72
}
70
73
74
+ // GroupDescription contains each described group.
71
75
type GroupDescription struct {
76
+ // Version defines the protocol version to use for encode and decode
72
77
Version int16
73
-
74
- Err KError
75
- GroupId string
76
- State string
77
- ProtocolType string
78
- Protocol string
79
- Members map [string ]* GroupMemberDescription
78
+ // Err contains the describe error as the KError type.
79
+ Err KError
80
+ // ErrorCode contains the describe error, or 0 if there was no error.
81
+ ErrorCode int16
82
+ // GroupId contains the group ID string.
83
+ GroupId string
84
+ // State contains the group state string, or the empty string.
85
+ State string
86
+ // ProtocolType contains the group protocol type, or the empty string.
87
+ ProtocolType string
88
+ // Protocol contains the group protocol data, or the empty string.
89
+ Protocol string
90
+ // Members contains the group members.
91
+ Members map [string ]* GroupMemberDescription
92
+ // AuthorizedOperations contains a 32-bit bitfield to represent authorized
93
+ // operations for this group.
80
94
AuthorizedOperations int32
81
95
}
82
96
83
- func (gd * GroupDescription ) encode (pe packetEncoder ) error {
84
- pe .putInt16 (int16 (gd .Err ))
97
+ func (gd * GroupDescription ) encode (pe packetEncoder , version int16 ) (err error ) {
98
+ gd .Version = version
99
+ pe .putInt16 (gd .ErrorCode )
85
100
86
101
if err := pe .putString (gd .GroupId ); err != nil {
87
102
return err
@@ -100,13 +115,8 @@ func (gd *GroupDescription) encode(pe packetEncoder) error {
100
115
return err
101
116
}
102
117
103
- for memberId , groupMemberDescription := range gd .Members {
104
- if err := pe .putString (memberId ); err != nil {
105
- return err
106
- }
107
- // encode with version
108
- groupMemberDescription .Version = gd .Version
109
- if err := groupMemberDescription .encode (pe ); err != nil {
118
+ for _ , block := range gd .Members {
119
+ if err := block .encode (pe , gd .Version ); err != nil {
110
120
return err
111
121
}
112
122
}
@@ -118,44 +128,38 @@ func (gd *GroupDescription) encode(pe packetEncoder) error {
118
128
return nil
119
129
}
120
130
121
- func (gd * GroupDescription ) decode (pd packetDecoder ) (err error ) {
122
- kerr , err := pd . getInt16 ()
123
- if err != nil {
131
+ func (gd * GroupDescription ) decode (pd packetDecoder , version int16 ) (err error ) {
132
+ gd . Version = version
133
+ if gd . ErrorCode , err = pd . getInt16 (); err != nil {
124
134
return err
125
135
}
126
136
127
- gd .Err = KError (kerr )
137
+ gd .Err = KError (gd . ErrorCode )
128
138
129
139
if gd .GroupId , err = pd .getString (); err != nil {
130
- return
140
+ return err
131
141
}
132
142
if gd .State , err = pd .getString (); err != nil {
133
- return
143
+ return err
134
144
}
135
145
if gd .ProtocolType , err = pd .getString (); err != nil {
136
- return
146
+ return err
137
147
}
138
148
if gd .Protocol , err = pd .getString (); err != nil {
139
- return
140
- }
141
-
142
- n , err := pd .getArrayLength ()
143
- if err != nil {
144
149
return err
145
150
}
146
151
147
- if n > 0 {
148
- gd .Members = make (map [string ]* GroupMemberDescription )
149
- for i := 0 ; i < n ; i ++ {
150
- memberId , err := pd .getString ()
151
- if err != nil {
152
+ if numMembers , err := pd .getArrayLength (); err != nil {
153
+ return err
154
+ } else if numMembers > 0 {
155
+ gd .Members = make (map [string ]* GroupMemberDescription , numMembers )
156
+ for i := 0 ; i < numMembers ; i ++ {
157
+ block := & GroupMemberDescription {}
158
+ if err := block .decode (pd , gd .Version ); err != nil {
152
159
return err
153
160
}
154
-
155
- gd .Members [memberId ] = new (GroupMemberDescription )
156
- gd .Members [memberId ].Version = gd .Version
157
- if err := gd .Members [memberId ].decode (pd ); err != nil {
158
- return err
161
+ if block != nil {
162
+ gd .Members [block .MemberId ] = block
159
163
}
160
164
}
161
165
}
@@ -169,17 +173,33 @@ func (gd *GroupDescription) decode(pd packetDecoder) (err error) {
169
173
return nil
170
174
}
171
175
176
+ // GroupMemberDescription contains the group members.
172
177
type GroupMemberDescription struct {
178
+ // Version defines the protocol version to use for encode and decode
173
179
Version int16
174
-
175
- GroupInstanceId * string
176
- ClientId string
177
- ClientHost string
178
- MemberMetadata []byte
180
+ // MemberId contains the member ID assigned by the group coordinator.
181
+ MemberId string
182
+ // GroupInstanceId contains the unique identifier of the consumer instance
183
+ // provided by end user.
184
+ GroupInstanceId * string
185
+ // ClientId contains the client ID used in the member's latest join group
186
+ // request.
187
+ ClientId string
188
+ // ClientHost contains the client host.
189
+ ClientHost string
190
+ // MemberMetadata contains the metadata corresponding to the current group
191
+ // protocol in use.
192
+ MemberMetadata []byte
193
+ // MemberAssignment contains the current assignment provided by the group
194
+ // leader.
179
195
MemberAssignment []byte
180
196
}
181
197
182
- func (gmd * GroupMemberDescription ) encode (pe packetEncoder ) error {
198
+ func (gmd * GroupMemberDescription ) encode (pe packetEncoder , version int16 ) (err error ) {
199
+ gmd .Version = version
200
+ if err := pe .putString (gmd .MemberId ); err != nil {
201
+ return err
202
+ }
183
203
if gmd .Version >= 4 {
184
204
if err := pe .putNullableString (gmd .GroupInstanceId ); err != nil {
185
205
return err
@@ -201,23 +221,27 @@ func (gmd *GroupMemberDescription) encode(pe packetEncoder) error {
201
221
return nil
202
222
}
203
223
204
- func (gmd * GroupMemberDescription ) decode (pd packetDecoder ) (err error ) {
224
+ func (gmd * GroupMemberDescription ) decode (pd packetDecoder , version int16 ) (err error ) {
225
+ gmd .Version = version
226
+ if gmd .MemberId , err = pd .getString (); err != nil {
227
+ return err
228
+ }
205
229
if gmd .Version >= 4 {
206
230
if gmd .GroupInstanceId , err = pd .getNullableString (); err != nil {
207
- return
231
+ return err
208
232
}
209
233
}
210
234
if gmd .ClientId , err = pd .getString (); err != nil {
211
- return
235
+ return err
212
236
}
213
237
if gmd .ClientHost , err = pd .getString (); err != nil {
214
- return
238
+ return err
215
239
}
216
240
if gmd .MemberMetadata , err = pd .getBytes (); err != nil {
217
- return
241
+ return err
218
242
}
219
243
if gmd .MemberAssignment , err = pd .getBytes (); err != nil {
220
- return
244
+ return err
221
245
}
222
246
223
247
return nil
0 commit comments