leave_group_request.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package sarama
  2. type MemberIdentity struct {
  3. MemberId string
  4. GroupInstanceId *string
  5. }
  6. type LeaveGroupRequest struct {
  7. Version int16
  8. GroupId string
  9. MemberId string // Removed in Version 3
  10. Members []MemberIdentity // Added in Version 3
  11. }
  12. func (r *LeaveGroupRequest) encode(pe packetEncoder) error {
  13. if err := pe.putString(r.GroupId); err != nil {
  14. return err
  15. }
  16. if r.Version < 3 {
  17. if err := pe.putString(r.MemberId); err != nil {
  18. return err
  19. }
  20. }
  21. if r.Version >= 3 {
  22. if err := pe.putArrayLength(len(r.Members)); err != nil {
  23. return err
  24. }
  25. for _, member := range r.Members {
  26. if err := pe.putString(member.MemberId); err != nil {
  27. return err
  28. }
  29. if err := pe.putNullableString(member.GroupInstanceId); err != nil {
  30. return err
  31. }
  32. }
  33. }
  34. return nil
  35. }
  36. func (r *LeaveGroupRequest) decode(pd packetDecoder, version int16) (err error) {
  37. r.Version = version
  38. if r.GroupId, err = pd.getString(); err != nil {
  39. return
  40. }
  41. if r.Version < 3 {
  42. if r.MemberId, err = pd.getString(); err != nil {
  43. return
  44. }
  45. }
  46. if r.Version >= 3 {
  47. memberCount, err := pd.getArrayLength()
  48. if err != nil {
  49. return err
  50. }
  51. r.Members = make([]MemberIdentity, memberCount)
  52. for i := 0; i < memberCount; i++ {
  53. memberIdentity := MemberIdentity{}
  54. if memberIdentity.MemberId, err = pd.getString(); err != nil {
  55. return err
  56. }
  57. if memberIdentity.GroupInstanceId, err = pd.getNullableString(); err != nil {
  58. return err
  59. }
  60. r.Members[i] = memberIdentity
  61. }
  62. }
  63. return nil
  64. }
  65. func (r *LeaveGroupRequest) key() int16 {
  66. return 13
  67. }
  68. func (r *LeaveGroupRequest) version() int16 {
  69. return r.Version
  70. }
  71. func (r *LeaveGroupRequest) headerVersion() int16 {
  72. return 1
  73. }
  74. func (r *LeaveGroupRequest) isValidVersion() bool {
  75. return r.Version >= 0 && r.Version <= 3
  76. }
  77. func (r *LeaveGroupRequest) requiredVersion() KafkaVersion {
  78. switch r.Version {
  79. case 3:
  80. return V2_4_0_0
  81. case 2:
  82. return V2_0_0_0
  83. case 1:
  84. return V0_11_0_0
  85. case 0:
  86. return V0_9_0_0
  87. default:
  88. return V2_4_0_0
  89. }
  90. }