alter_client_quotas_response.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package sarama
  2. import (
  3. "time"
  4. )
  5. // AlterClientQuotas Response (Version: 0) => throttle_time_ms [entries]
  6. // throttle_time_ms => INT32
  7. // entries => error_code error_message [entity]
  8. // error_code => INT16
  9. // error_message => NULLABLE_STRING
  10. // entity => entity_type entity_name
  11. // entity_type => STRING
  12. // entity_name => NULLABLE_STRING
  13. type AlterClientQuotasResponse struct {
  14. Version int16
  15. ThrottleTime time.Duration // The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
  16. Entries []AlterClientQuotasEntryResponse // The quota configuration entries altered.
  17. }
  18. type AlterClientQuotasEntryResponse struct {
  19. ErrorCode KError // The error code, or `0` if the quota alteration succeeded.
  20. ErrorMsg *string // The error message, or `null` if the quota alteration succeeded.
  21. Entity []QuotaEntityComponent // The quota entity altered.
  22. }
  23. func (a *AlterClientQuotasResponse) encode(pe packetEncoder) error {
  24. // ThrottleTime
  25. pe.putInt32(int32(a.ThrottleTime / time.Millisecond))
  26. // Entries
  27. if err := pe.putArrayLength(len(a.Entries)); err != nil {
  28. return err
  29. }
  30. for _, e := range a.Entries {
  31. if err := e.encode(pe); err != nil {
  32. return err
  33. }
  34. }
  35. return nil
  36. }
  37. func (a *AlterClientQuotasResponse) decode(pd packetDecoder, version int16) error {
  38. // ThrottleTime
  39. throttleTime, err := pd.getInt32()
  40. if err != nil {
  41. return err
  42. }
  43. a.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
  44. // Entries
  45. entryCount, err := pd.getArrayLength()
  46. if err != nil {
  47. return err
  48. }
  49. if entryCount > 0 {
  50. a.Entries = make([]AlterClientQuotasEntryResponse, entryCount)
  51. for i := range a.Entries {
  52. e := AlterClientQuotasEntryResponse{}
  53. if err = e.decode(pd, version); err != nil {
  54. return err
  55. }
  56. a.Entries[i] = e
  57. }
  58. } else {
  59. a.Entries = []AlterClientQuotasEntryResponse{}
  60. }
  61. return nil
  62. }
  63. func (a *AlterClientQuotasEntryResponse) encode(pe packetEncoder) error {
  64. // ErrorCode
  65. pe.putInt16(int16(a.ErrorCode))
  66. // ErrorMsg
  67. if err := pe.putNullableString(a.ErrorMsg); err != nil {
  68. return err
  69. }
  70. // Entity
  71. if err := pe.putArrayLength(len(a.Entity)); err != nil {
  72. return err
  73. }
  74. for _, component := range a.Entity {
  75. if err := component.encode(pe); err != nil {
  76. return err
  77. }
  78. }
  79. return nil
  80. }
  81. func (a *AlterClientQuotasEntryResponse) decode(pd packetDecoder, version int16) error {
  82. // ErrorCode
  83. errCode, err := pd.getInt16()
  84. if err != nil {
  85. return err
  86. }
  87. a.ErrorCode = KError(errCode)
  88. // ErrorMsg
  89. errMsg, err := pd.getNullableString()
  90. if err != nil {
  91. return err
  92. }
  93. a.ErrorMsg = errMsg
  94. // Entity
  95. componentCount, err := pd.getArrayLength()
  96. if err != nil {
  97. return err
  98. }
  99. if componentCount > 0 {
  100. a.Entity = make([]QuotaEntityComponent, componentCount)
  101. for i := 0; i < componentCount; i++ {
  102. component := QuotaEntityComponent{}
  103. if err := component.decode(pd, version); err != nil {
  104. return err
  105. }
  106. a.Entity[i] = component
  107. }
  108. } else {
  109. a.Entity = []QuotaEntityComponent{}
  110. }
  111. return nil
  112. }
  113. func (a *AlterClientQuotasResponse) key() int16 {
  114. return 49
  115. }
  116. func (a *AlterClientQuotasResponse) version() int16 {
  117. return a.Version
  118. }
  119. func (a *AlterClientQuotasResponse) headerVersion() int16 {
  120. return 0
  121. }
  122. func (a *AlterClientQuotasResponse) isValidVersion() bool {
  123. return a.Version == 0
  124. }
  125. func (a *AlterClientQuotasResponse) requiredVersion() KafkaVersion {
  126. return V2_6_0_0
  127. }
  128. func (r *AlterClientQuotasResponse) throttleTime() time.Duration {
  129. return r.ThrottleTime
  130. }