list_groups_response.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package sarama
  2. type ListGroupsResponse struct {
  3. Err KError
  4. Groups map[string]string
  5. }
  6. func (r *ListGroupsResponse) encode(pe packetEncoder) error {
  7. pe.putInt16(int16(r.Err))
  8. if err := pe.putArrayLength(len(r.Groups)); err != nil {
  9. return err
  10. }
  11. for groupId, protocolType := range r.Groups {
  12. if err := pe.putString(groupId); err != nil {
  13. return err
  14. }
  15. if err := pe.putString(protocolType); err != nil {
  16. return err
  17. }
  18. }
  19. return nil
  20. }
  21. func (r *ListGroupsResponse) decode(pd packetDecoder, version int16) error {
  22. kerr, err := pd.getInt16()
  23. if err != nil {
  24. return err
  25. }
  26. r.Err = KError(kerr)
  27. n, err := pd.getArrayLength()
  28. if err != nil {
  29. return err
  30. }
  31. if n == 0 {
  32. return nil
  33. }
  34. r.Groups = make(map[string]string)
  35. for i := 0; i < n; i++ {
  36. groupId, err := pd.getString()
  37. if err != nil {
  38. return err
  39. }
  40. protocolType, err := pd.getString()
  41. if err != nil {
  42. return err
  43. }
  44. r.Groups[groupId] = protocolType
  45. }
  46. return nil
  47. }
  48. func (r *ListGroupsResponse) key() int16 {
  49. return 16
  50. }
  51. func (r *ListGroupsResponse) version() int16 {
  52. return 0
  53. }
  54. func (r *ListGroupsResponse) requiredVersion() KafkaVersion {
  55. return V0_9_0_0
  56. }