github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/protocol/describegroups/describegroups.go (about) 1 package describegroups 2 3 import ( 4 "github.com/segmentio/kafka-go/protocol" 5 ) 6 7 func init() { 8 protocol.Register(&Request{}, &Response{}) 9 } 10 11 // Detailed API definition: https://kafka.apache.org/protocol#The_Messages_DescribeGroups 12 type Request struct { 13 Groups []string `kafka:"min=v0,max=v4"` 14 IncludeAuthorizedOperations bool `kafka:"min=v3,max=v4"` 15 } 16 17 func (r *Request) ApiKey() protocol.ApiKey { return protocol.DescribeGroups } 18 19 func (r *Request) Group() string { 20 return r.Groups[0] 21 } 22 23 func (r *Request) Split(cluster protocol.Cluster) ( 24 []protocol.Message, 25 protocol.Merger, 26 error, 27 ) { 28 messages := []protocol.Message{} 29 30 // Split requests by group since they'll need to go to different coordinators. 31 for _, group := range r.Groups { 32 messages = append( 33 messages, 34 &Request{ 35 Groups: []string{group}, 36 IncludeAuthorizedOperations: r.IncludeAuthorizedOperations, 37 }, 38 ) 39 } 40 41 return messages, new(Response), nil 42 } 43 44 type Response struct { 45 ThrottleTimeMs int32 `kafka:"min=v1,max=v4"` 46 Groups []ResponseGroup `kafka:"min=v0,max=v4"` 47 } 48 49 type ResponseGroup struct { 50 ErrorCode int16 `kafka:"min=v0,max=v4"` 51 GroupID string `kafka:"min=v0,max=v4"` 52 GroupState string `kafka:"min=v0,max=v4"` 53 ProtocolType string `kafka:"min=v0,max=v4"` 54 ProtocolData string `kafka:"min=v0,max=v4"` 55 Members []ResponseGroupMember `kafka:"min=v0,max=v4"` 56 AuthorizedOperations int32 `kafka:"min=v3,max=v4"` 57 } 58 59 type ResponseGroupMember struct { 60 MemberID string `kafka:"min=v0,max=v4"` 61 GroupInstanceID string `kafka:"min=v4,max=v4,nullable"` 62 ClientID string `kafka:"min=v0,max=v4"` 63 ClientHost string `kafka:"min=v0,max=v4"` 64 MemberMetadata []byte `kafka:"min=v0,max=v4"` 65 MemberAssignment []byte `kafka:"min=v0,max=v4"` 66 } 67 68 func (r *Response) ApiKey() protocol.ApiKey { return protocol.DescribeGroups } 69 70 func (r *Response) Merge(requests []protocol.Message, results []interface{}) ( 71 protocol.Message, 72 error, 73 ) { 74 response := &Response{} 75 76 for _, result := range results { 77 m, err := protocol.Result(result) 78 if err != nil { 79 return nil, err 80 } 81 response.Groups = append(response.Groups, m.(*Response).Groups...) 82 } 83 84 return response, nil 85 }