describe_groups_response.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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) requiredVersion() KafkaVersion {
  37. return V0_9_0_0
  38. }
  39. type GroupDescription struct {
  40. Err KError
  41. GroupID string
  42. State string
  43. ProtocolType string
  44. Protocol string
  45. Members map[string]*GroupMemberDescription
  46. }
  47. func (gd *GroupDescription) encode(pe packetEncoder) error {
  48. pe.putInt16(int16(gd.Err))
  49. if err := pe.putString(gd.GroupID); err != nil {
  50. return err
  51. }
  52. if err := pe.putString(gd.State); err != nil {
  53. return err
  54. }
  55. if err := pe.putString(gd.ProtocolType); err != nil {
  56. return err
  57. }
  58. if err := pe.putString(gd.Protocol); err != nil {
  59. return err
  60. }
  61. if err := pe.putArrayLength(len(gd.Members)); err != nil {
  62. return err
  63. }
  64. for memberID, groupMemberDescription := range gd.Members {
  65. if err := pe.putString(memberID); err != nil {
  66. return err
  67. }
  68. if err := groupMemberDescription.encode(pe); err != nil {
  69. return err
  70. }
  71. }
  72. return nil
  73. }
  74. func (gd *GroupDescription) decode(pd packetDecoder) (err error) {
  75. kerr, err := pd.getInt16()
  76. if err != nil {
  77. return err
  78. }
  79. gd.Err = KError(kerr)
  80. if gd.GroupID, err = pd.getString(); err != nil {
  81. return
  82. }
  83. if gd.State, err = pd.getString(); err != nil {
  84. return
  85. }
  86. if gd.ProtocolType, err = pd.getString(); err != nil {
  87. return
  88. }
  89. if gd.Protocol, err = pd.getString(); err != nil {
  90. return
  91. }
  92. n, err := pd.getArrayLength()
  93. if err != nil {
  94. return err
  95. }
  96. if n == 0 {
  97. return nil
  98. }
  99. gd.Members = make(map[string]*GroupMemberDescription)
  100. for i := 0; i < n; i++ {
  101. memberID, err := pd.getString()
  102. if err != nil {
  103. return err
  104. }
  105. gd.Members[memberID] = new(GroupMemberDescription)
  106. if err := gd.Members[memberID].decode(pd); err != nil {
  107. return err
  108. }
  109. }
  110. return nil
  111. }
  112. type GroupMemberDescription struct {
  113. ClientID string
  114. ClientHost string
  115. MemberMetadata []byte
  116. MemberAssignment []byte
  117. }
  118. func (gmd *GroupMemberDescription) encode(pe packetEncoder) error {
  119. if err := pe.putString(gmd.ClientID); err != nil {
  120. return err
  121. }
  122. if err := pe.putString(gmd.ClientHost); err != nil {
  123. return err
  124. }
  125. if err := pe.putBytes(gmd.MemberMetadata); err != nil {
  126. return err
  127. }
  128. if err := pe.putBytes(gmd.MemberAssignment); err != nil {
  129. return err
  130. }
  131. return nil
  132. }
  133. func (gmd *GroupMemberDescription) decode(pd packetDecoder) (err error) {
  134. if gmd.ClientID, err = pd.getString(); err != nil {
  135. return
  136. }
  137. if gmd.ClientHost, err = pd.getString(); err != nil {
  138. return
  139. }
  140. if gmd.MemberMetadata, err = pd.getBytes(); err != nil {
  141. return
  142. }
  143. if gmd.MemberAssignment, err = pd.getBytes(); err != nil {
  144. return
  145. }
  146. return nil
  147. }
  148. func (gmd *GroupMemberDescription) GetMemberAssignment() (*ConsumerGroupMemberAssignment, error) {
  149. assignment := new(ConsumerGroupMemberAssignment)
  150. err := decode(gmd.MemberAssignment, assignment)
  151. return assignment, err
  152. }
  153. func (gmd *GroupMemberDescription) GetMemberMetadata() (*ConsumerGroupMemberMetadata, error) {
  154. metadata := new(ConsumerGroupMemberMetadata)
  155. err := decode(gmd.MemberMetadata, metadata)
  156. return metadata, err
  157. }