Skip to content

Commit

Permalink
Add DescribeGroup request and response pair.
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanbergen committed Dec 7, 2015
1 parent 15b6e74 commit 6022982
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 0 deletions.
22 changes: 22 additions & 0 deletions describe_groups_request.go
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
}
158 changes: 158 additions & 0 deletions describe_groups_response.go
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
}

0 comments on commit 6022982

Please sign in to comment.