delete_groups_response.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package sarama
  2. import (
  3. "time"
  4. )
  5. type DeleteGroupsResponse struct {
  6. Version int16
  7. ThrottleTime time.Duration
  8. GroupErrorCodes map[string]KError
  9. }
  10. func (r *DeleteGroupsResponse) encode(pe packetEncoder) error {
  11. pe.putInt32(int32(r.ThrottleTime / time.Millisecond))
  12. if err := pe.putArrayLength(len(r.GroupErrorCodes)); err != nil {
  13. return err
  14. }
  15. for groupID, errorCode := range r.GroupErrorCodes {
  16. if err := pe.putString(groupID); err != nil {
  17. return err
  18. }
  19. pe.putInt16(int16(errorCode))
  20. }
  21. return nil
  22. }
  23. func (r *DeleteGroupsResponse) decode(pd packetDecoder, version int16) error {
  24. throttleTime, err := pd.getInt32()
  25. if err != nil {
  26. return err
  27. }
  28. r.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
  29. n, err := pd.getArrayLength()
  30. if err != nil {
  31. return err
  32. }
  33. if n == 0 {
  34. return nil
  35. }
  36. r.GroupErrorCodes = make(map[string]KError, n)
  37. for i := 0; i < n; i++ {
  38. groupID, err := pd.getString()
  39. if err != nil {
  40. return err
  41. }
  42. errorCode, err := pd.getInt16()
  43. if err != nil {
  44. return err
  45. }
  46. r.GroupErrorCodes[groupID] = KError(errorCode)
  47. }
  48. return nil
  49. }
  50. func (r *DeleteGroupsResponse) key() int16 {
  51. return 42
  52. }
  53. func (r *DeleteGroupsResponse) version() int16 {
  54. return r.Version
  55. }
  56. func (r *DeleteGroupsResponse) headerVersion() int16 {
  57. return 0
  58. }
  59. func (r *DeleteGroupsResponse) isValidVersion() bool {
  60. return r.Version >= 0 && r.Version <= 1
  61. }
  62. func (r *DeleteGroupsResponse) requiredVersion() KafkaVersion {
  63. switch r.Version {
  64. case 1:
  65. return V2_0_0_0
  66. case 0:
  67. return V1_1_0_0
  68. default:
  69. return V2_0_0_0
  70. }
  71. }
  72. func (r *DeleteGroupsResponse) throttleTime() time.Duration {
  73. return r.ThrottleTime
  74. }