join_group_response.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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) requiredVersion() KafkaVersion {
  103. switch r.Version {
  104. case 2:
  105. return V0_11_0_0
  106. case 1:
  107. return V0_10_1_0
  108. default:
  109. return V0_9_0_0
  110. }
  111. }