describe_groups_response.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package sarama
  2. type DescribeGroupsResponse struct {
  3. Groups []*GroupDescription
  4. }
  5. func (r *DescribeGroupsResponse) encode(pe packetEncoder) error {
  6. if err := pe.putArrayLength(len(r.Groups)); err != nil {
  7. return err
  8. }
  9. for _, groupDescription := range r.Groups {
  10. if err := groupDescription.encode(pe); err != nil {
  11. return err
  12. }
  13. }
  14. return nil
  15. }
  16. func (r *DescribeGroupsResponse) decode(pd packetDecoder, version int16) (err error) {
  17. n, err := pd.getArrayLength()
  18. if err != nil {
  19. return err
  20. }
  21. r.Groups = make([]*GroupDescription, n)
  22. for i := 0; i < n; i++ {
  23. r.Groups[i] = new(GroupDescription)
  24. if err := r.Groups[i].decode(pd); err != nil {
  25. return err
  26. }
  27. }
  28. return nil
  29. }
  30. func (r *DescribeGroupsResponse) key() int16 {
  31. return 15
  32. }
  33. func (r *DescribeGroupsResponse) version() int16 {
  34. return 0
  35. }
  36. func (r *DescribeGroupsResponse) headerVersion() int16 {
  37. return 0
  38. }
  39. func (r *DescribeGroupsResponse) requiredVersion() KafkaVersion {
  40. return V0_9_0_0
  41. }
  42. type GroupDescription struct {
  43. Err KError
  44. GroupId string
  45. State string
  46. ProtocolType string
  47. Protocol string
  48. Members map[string]*GroupMemberDescription
  49. }
  50. func (gd *GroupDescription) encode(pe packetEncoder) error {
  51. pe.putInt16(int16(gd.Err))
  52. if err := pe.putString(gd.GroupId); err != nil {
  53. return err
  54. }
  55. if err := pe.putString(gd.State); err != nil {
  56. return err
  57. }
  58. if err := pe.putString(gd.ProtocolType); err != nil {
  59. return err
  60. }
  61. if err := pe.putString(gd.Protocol); err != nil {
  62. return err
  63. }
  64. if err := pe.putArrayLength(len(gd.Members)); err != nil {
  65. return err
  66. }
  67. for memberId, groupMemberDescription := range gd.Members {
  68. if err := pe.putString(memberId); err != nil {
  69. return err
  70. }
  71. if err := groupMemberDescription.encode(pe); err != nil {
  72. return err
  73. }
  74. }
  75. return nil
  76. }
  77. func (gd *GroupDescription) decode(pd packetDecoder) (err error) {
  78. kerr, err := pd.getInt16()
  79. if err != nil {
  80. return err
  81. }
  82. gd.Err = KError(kerr)
  83. if gd.GroupId, err = pd.getString(); err != nil {
  84. return
  85. }
  86. if gd.State, err = pd.getString(); err != nil {
  87. return
  88. }
  89. if gd.ProtocolType, err = pd.getString(); err != nil {
  90. return
  91. }
  92. if gd.Protocol, err = pd.getString(); err != nil {
  93. return
  94. }
  95. n, err := pd.getArrayLength()
  96. if err != nil {
  97. return err
  98. }
  99. if n == 0 {
  100. return nil
  101. }
  102. gd.Members = make(map[string]*GroupMemberDescription)
  103. for i := 0; i < n; i++ {
  104. memberId, err := pd.getString()
  105. if err != nil {
  106. return err
  107. }
  108. gd.Members[memberId] = new(GroupMemberDescription)
  109. if err := gd.Members[memberId].decode(pd); err != nil {
  110. return err
  111. }
  112. }
  113. return nil
  114. }
  115. type GroupMemberDescription struct {
  116. ClientId string
  117. ClientHost string
  118. MemberMetadata []byte
  119. MemberAssignment []byte
  120. }
  121. func (gmd *GroupMemberDescription) encode(pe packetEncoder) error {
  122. if err := pe.putString(gmd.ClientId); err != nil {
  123. return err
  124. }
  125. if err := pe.putString(gmd.ClientHost); err != nil {
  126. return err
  127. }
  128. if err := pe.putBytes(gmd.MemberMetadata); err != nil {
  129. return err
  130. }
  131. if err := pe.putBytes(gmd.MemberAssignment); err != nil {
  132. return err
  133. }
  134. return nil
  135. }
  136. func (gmd *GroupMemberDescription) decode(pd packetDecoder) (err error) {
  137. if gmd.ClientId, err = pd.getString(); err != nil {
  138. return
  139. }
  140. if gmd.ClientHost, err = pd.getString(); err != nil {
  141. return
  142. }
  143. if gmd.MemberMetadata, err = pd.getBytes(); err != nil {
  144. return
  145. }
  146. if gmd.MemberAssignment, err = pd.getBytes(); err != nil {
  147. return
  148. }
  149. return nil
  150. }
  151. func (gmd *GroupMemberDescription) GetMemberAssignment() (*ConsumerGroupMemberAssignment, error) {
  152. assignment := new(ConsumerGroupMemberAssignment)
  153. err := decode(gmd.MemberAssignment, assignment)
  154. return assignment, err
  155. }
  156. func (gmd *GroupMemberDescription) GetMemberMetadata() (*ConsumerGroupMemberMetadata, error) {
  157. metadata := new(ConsumerGroupMemberMetadata)
  158. err := decode(gmd.MemberMetadata, metadata)
  159. return metadata, err
  160. }