consumer_group_members.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package sarama
  2. type ConsumerGroupMemberMetadata struct {
  3. Version int16
  4. Topics []string
  5. UserData []byte
  6. }
  7. func (m *ConsumerGroupMemberMetadata) encode(pe packetEncoder) error {
  8. pe.putInt16(m.Version)
  9. if err := pe.putStringArray(m.Topics); err != nil {
  10. return err
  11. }
  12. if err := pe.putBytes(m.UserData); err != nil {
  13. return err
  14. }
  15. return nil
  16. }
  17. func (m *ConsumerGroupMemberMetadata) decode(pd packetDecoder) (err error) {
  18. if m.Version, err = pd.getInt16(); err != nil {
  19. return
  20. }
  21. if m.Topics, err = pd.getStringArray(); err != nil {
  22. return
  23. }
  24. if m.UserData, err = pd.getBytes(); err != nil {
  25. return
  26. }
  27. return nil
  28. }
  29. type ConsumerGroupMemberAssignment struct {
  30. Version int16
  31. Topics map[string][]int32
  32. UserData []byte
  33. }
  34. func (m *ConsumerGroupMemberAssignment) encode(pe packetEncoder) error {
  35. pe.putInt16(m.Version)
  36. if err := pe.putArrayLength(len(m.Topics)); err != nil {
  37. return err
  38. }
  39. for topic, partitions := range m.Topics {
  40. if err := pe.putString(topic); err != nil {
  41. return err
  42. }
  43. if err := pe.putInt32Array(partitions); err != nil {
  44. return err
  45. }
  46. }
  47. if err := pe.putBytes(m.UserData); err != nil {
  48. return err
  49. }
  50. return nil
  51. }
  52. func (m *ConsumerGroupMemberAssignment) decode(pd packetDecoder) (err error) {
  53. if m.Version, err = pd.getInt16(); err != nil {
  54. return
  55. }
  56. var topicLen int
  57. if topicLen, err = pd.getArrayLength(); err != nil {
  58. return
  59. }
  60. m.Topics = make(map[string][]int32, topicLen)
  61. for i := 0; i < topicLen; i++ {
  62. var topic string
  63. if topic, err = pd.getString(); err != nil {
  64. return
  65. }
  66. if m.Topics[topic], err = pd.getInt32Array(); err != nil {
  67. return
  68. }
  69. }
  70. if m.UserData, err = pd.getBytes(); err != nil {
  71. return
  72. }
  73. return nil
  74. }