-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DescribeGroup request and response pair.
- Loading branch information
1 parent
15b6e74
commit 6022982
Showing
2 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sarama | ||
|
||
type DescribeGroupsRequest struct { | ||
Groups []string | ||
} | ||
|
||
func (r *DescribeGroupsRequest) encode(pe packetEncoder) error { | ||
return pe.putStringArray(r.Groups) | ||
} | ||
|
||
func (r *DescribeGroupsRequest) decode(pd packetDecoder) (err error) { | ||
r.Groups, err = pd.getStringArray() | ||
return | ||
} | ||
|
||
func (r *DescribeGroupsRequest) key() int16 { | ||
return 15 | ||
} | ||
|
||
func (r *DescribeGroupsRequest) version() int16 { | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package sarama | ||
|
||
type DescribeGroupsResponse struct { | ||
Groups []*GroupDescription | ||
} | ||
|
||
func (r *DescribeGroupsResponse) encode(pe packetEncoder) error { | ||
if err := pe.putArrayLength(len(r.Groups)); err != nil { | ||
return err | ||
} | ||
|
||
for _, groupDescription := range r.Groups { | ||
if err := groupDescription.encode(pe); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *DescribeGroupsResponse) decode(pd packetDecoder) (err error) { | ||
n, err := pd.getArrayLength() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
r.Groups = make([]*GroupDescription, n) | ||
for i := 0; i < n; i++ { | ||
r.Groups[i] = new(GroupDescription) | ||
if err := r.Groups[i].decode(pd); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type GroupDescription struct { | ||
Err KError | ||
GroupId string | ||
State string | ||
ProtocolType string | ||
Protocol string | ||
Members []*GroupMemberDescription | ||
} | ||
|
||
func (gd *GroupDescription) encode(pe packetEncoder) error { | ||
pe.putInt16(int16(gd.Err)) | ||
|
||
if err := pe.putString(gd.GroupId); err != nil { | ||
return err | ||
} | ||
if err := pe.putString(gd.State); err != nil { | ||
return err | ||
} | ||
if err := pe.putString(gd.ProtocolType); err != nil { | ||
return err | ||
} | ||
if err := pe.putString(gd.Protocol); err != nil { | ||
return err | ||
} | ||
|
||
if err := pe.putArrayLength(len(gd.Members)); err != nil { | ||
return err | ||
} | ||
|
||
for _, groupMemberDescription := range gd.Members { | ||
if err := groupMemberDescription.encode(pe); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (gd *GroupDescription) decode(pd packetDecoder) (err error) { | ||
if kerr, err := pd.getInt16(); err != nil { | ||
return err | ||
} else { | ||
gd.Err = KError(kerr) | ||
} | ||
|
||
if gd.GroupId, err = pd.getString(); err != nil { | ||
return | ||
} | ||
if gd.State, err = pd.getString(); err != nil { | ||
return | ||
} | ||
if gd.ProtocolType, err = pd.getString(); err != nil { | ||
return | ||
} | ||
if gd.Protocol, err = pd.getString(); err != nil { | ||
return | ||
} | ||
|
||
n, err := pd.getArrayLength() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
gd.Members = make([]*GroupMemberDescription, n) | ||
for i := 0; i < n; i++ { | ||
gd.Members[i] = new(GroupMemberDescription) | ||
if err := gd.Members[i].decode(pd); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type GroupMemberDescription struct { | ||
MemberId string | ||
ClientId string | ||
ClientHost string | ||
MemberMetadata []byte | ||
MemberAssignment []byte | ||
} | ||
|
||
func (gmd *GroupMemberDescription) encode(pe packetEncoder) error { | ||
if err := pe.putString(gmd.MemberId); err != nil { | ||
return err | ||
} | ||
if err := pe.putString(gmd.ClientId); err != nil { | ||
return err | ||
} | ||
if err := pe.putString(gmd.ClientHost); err != nil { | ||
return err | ||
} | ||
if err := pe.putBytes(gmd.MemberMetadata); err != nil { | ||
return err | ||
} | ||
if err := pe.putBytes(gmd.MemberAssignment); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (gmd *GroupMemberDescription) decode(pd packetDecoder) (err error) { | ||
if gmd.MemberId, err = pd.getString(); err != nil { | ||
return | ||
} | ||
if gmd.ClientId, err = pd.getString(); err != nil { | ||
return | ||
} | ||
if gmd.ClientHost, err = pd.getString(); err != nil { | ||
return | ||
} | ||
if gmd.MemberMetadata, err = pd.getBytes(); err != nil { | ||
return | ||
} | ||
if gmd.MemberAssignment, err = pd.getBytes(); err != nil { | ||
return | ||
} | ||
|
||
return nil | ||
} |