join_group_response.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package sarama
  2. type JoinGroupResponse struct {
  3. Version int16
  4. ThrottleTime int32
  5. Err KError
  6. GenerationId int32
  7. GroupProtocol string
  8. LeaderId string
  9. MemberId string
  10. Members map[string][]byte
  11. }
  12. func (r *JoinGroupResponse) GetMembers() (map[string]ConsumerGroupMemberMetadata, error) {
  13. members := make(map[string]ConsumerGroupMemberMetadata, len(r.Members))
  14. for id, bin := range r.Members {
  15. meta := new(ConsumerGroupMemberMetadata)
  16. if err := decode(bin, meta); err != nil {
  17. return nil, err
  18. }
  19. members[id] = *meta
  20. }
  21. return members, nil
  22. }
  23. func (r *JoinGroupResponse) encode(pe packetEncoder) error {
  24. if r.Version >= 2 {
  25. pe.putInt32(r.ThrottleTime)
  26. }
  27. pe.putInt16(int16(r.Err))
  28. pe.putInt32(r.GenerationId)
  29. if err := pe.putString(r.GroupProtocol); err != nil {
  30. return err
  31. }
  32. if err := pe.putString(r.LeaderId); err != nil {
  33. return err
  34. }
  35. if err := pe.putString(r.MemberId); err != nil {
  36. return err
  37. }
  38. if err := pe.putArrayLength(len(r.Members)); err != nil {
  39. return err
  40. }
  41. for memberId, memberMetadata := range r.Members {
  42. if err := pe.putString(memberId); err != nil {
  43. return err
  44. }
  45. if err := pe.putBytes(memberMetadata); err != nil {
  46. return err
  47. }
  48. }
  49. return nil
  50. }
  51. func (r *JoinGroupResponse) decode(pd packetDecoder, version int16) (err error) {
  52. r.Version = version
  53. if version >= 2 {
  54. if r.ThrottleTime, err = pd.getInt32(); err != nil {
  55. return
  56. }
  57. }
  58. kerr, err := pd.getInt16()
  59. if err != nil {
  60. return err
  61. }
  62. r.Err = KError(kerr)
  63. if r.GenerationId, err = pd.getInt32(); err != nil {
  64. return
  65. }
  66. if r.GroupProtocol, err = pd.getString(); err != nil {
  67. return
  68. }
  69. if r.LeaderId, err = pd.getString(); err != nil {
  70. return
  71. }
  72. if r.MemberId, err = pd.getString(); err != nil {
  73. return
  74. }
  75. n, err := pd.getArrayLength()
  76. if err != nil {
  77. return err
  78. }
  79. if n == 0 {
  80. return nil
  81. }
  82. r.Members = make(map[string][]byte)
  83. for i := 0; i < n; i++ {
  84. memberId, err := pd.getString()
  85. if err != nil {
  86. return err
  87. }
  88. memberMetadata, err := pd.getBytes()
  89. if err != nil {
  90. return err
  91. }
  92. r.Members[memberId] = memberMetadata
  93. }
  94. return nil
  95. }
  96. func (r *JoinGroupResponse) key() int16 {
  97. return 11
  98. }
  99. func (r *JoinGroupResponse) version() int16 {
  100. return r.Version
  101. }
  102. func (r *JoinGroupResponse) headerVersion() int16 {
  103. return 0
  104. }
  105. func (r *JoinGroupResponse) requiredVersion() KafkaVersion {
  106. switch r.Version {
  107. case 2:
  108. return V0_11_0_0
  109. case 1:
  110. return V0_10_1_0
  111. default:
  112. return V0_9_0_0
  113. }
  114. }