alter_client_quotas_request.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package sarama
  2. // AlterClientQuotas Request (Version: 0) => [entries] validate_only
  3. // entries => [entity] [ops]
  4. // entity => entity_type entity_name
  5. // entity_type => STRING
  6. // entity_name => NULLABLE_STRING
  7. // ops => key value remove
  8. // key => STRING
  9. // value => FLOAT64
  10. // remove => BOOLEAN
  11. // validate_only => BOOLEAN
  12. type AlterClientQuotasRequest struct {
  13. Version int16
  14. Entries []AlterClientQuotasEntry // The quota configuration entries to alter.
  15. ValidateOnly bool // Whether the alteration should be validated, but not performed.
  16. }
  17. type AlterClientQuotasEntry struct {
  18. Entity []QuotaEntityComponent // The quota entity to alter.
  19. Ops []ClientQuotasOp // An individual quota configuration entry to alter.
  20. }
  21. type ClientQuotasOp struct {
  22. Key string // The quota configuration key.
  23. Value float64 // The value to set, otherwise ignored if the value is to be removed.
  24. Remove bool // Whether the quota configuration value should be removed, otherwise set.
  25. }
  26. func (a *AlterClientQuotasRequest) encode(pe packetEncoder) error {
  27. // Entries
  28. if err := pe.putArrayLength(len(a.Entries)); err != nil {
  29. return err
  30. }
  31. for _, e := range a.Entries {
  32. if err := e.encode(pe); err != nil {
  33. return err
  34. }
  35. }
  36. // ValidateOnly
  37. pe.putBool(a.ValidateOnly)
  38. return nil
  39. }
  40. func (a *AlterClientQuotasRequest) decode(pd packetDecoder, version int16) error {
  41. // Entries
  42. entryCount, err := pd.getArrayLength()
  43. if err != nil {
  44. return err
  45. }
  46. if entryCount > 0 {
  47. a.Entries = make([]AlterClientQuotasEntry, entryCount)
  48. for i := range a.Entries {
  49. e := AlterClientQuotasEntry{}
  50. if err = e.decode(pd, version); err != nil {
  51. return err
  52. }
  53. a.Entries[i] = e
  54. }
  55. } else {
  56. a.Entries = []AlterClientQuotasEntry{}
  57. }
  58. // ValidateOnly
  59. validateOnly, err := pd.getBool()
  60. if err != nil {
  61. return err
  62. }
  63. a.ValidateOnly = validateOnly
  64. return nil
  65. }
  66. func (a *AlterClientQuotasEntry) encode(pe packetEncoder) error {
  67. // Entity
  68. if err := pe.putArrayLength(len(a.Entity)); err != nil {
  69. return err
  70. }
  71. for _, component := range a.Entity {
  72. if err := component.encode(pe); err != nil {
  73. return err
  74. }
  75. }
  76. // Ops
  77. if err := pe.putArrayLength(len(a.Ops)); err != nil {
  78. return err
  79. }
  80. for _, o := range a.Ops {
  81. if err := o.encode(pe); err != nil {
  82. return err
  83. }
  84. }
  85. return nil
  86. }
  87. func (a *AlterClientQuotasEntry) decode(pd packetDecoder, version int16) error {
  88. // Entity
  89. componentCount, err := pd.getArrayLength()
  90. if err != nil {
  91. return err
  92. }
  93. if componentCount > 0 {
  94. a.Entity = make([]QuotaEntityComponent, componentCount)
  95. for i := 0; i < componentCount; i++ {
  96. component := QuotaEntityComponent{}
  97. if err := component.decode(pd, version); err != nil {
  98. return err
  99. }
  100. a.Entity[i] = component
  101. }
  102. } else {
  103. a.Entity = []QuotaEntityComponent{}
  104. }
  105. // Ops
  106. opCount, err := pd.getArrayLength()
  107. if err != nil {
  108. return err
  109. }
  110. if opCount > 0 {
  111. a.Ops = make([]ClientQuotasOp, opCount)
  112. for i := range a.Ops {
  113. c := ClientQuotasOp{}
  114. if err = c.decode(pd, version); err != nil {
  115. return err
  116. }
  117. a.Ops[i] = c
  118. }
  119. } else {
  120. a.Ops = []ClientQuotasOp{}
  121. }
  122. return nil
  123. }
  124. func (c *ClientQuotasOp) encode(pe packetEncoder) error {
  125. // Key
  126. if err := pe.putString(c.Key); err != nil {
  127. return err
  128. }
  129. // Value
  130. pe.putFloat64(c.Value)
  131. // Remove
  132. pe.putBool(c.Remove)
  133. return nil
  134. }
  135. func (c *ClientQuotasOp) decode(pd packetDecoder, version int16) error {
  136. // Key
  137. key, err := pd.getString()
  138. if err != nil {
  139. return err
  140. }
  141. c.Key = key
  142. // Value
  143. value, err := pd.getFloat64()
  144. if err != nil {
  145. return err
  146. }
  147. c.Value = value
  148. // Remove
  149. remove, err := pd.getBool()
  150. if err != nil {
  151. return err
  152. }
  153. c.Remove = remove
  154. return nil
  155. }
  156. func (a *AlterClientQuotasRequest) key() int16 {
  157. return 49
  158. }
  159. func (a *AlterClientQuotasRequest) version() int16 {
  160. return a.Version
  161. }
  162. func (a *AlterClientQuotasRequest) headerVersion() int16 {
  163. return 1
  164. }
  165. func (a *AlterClientQuotasRequest) isValidVersion() bool {
  166. return a.Version == 0
  167. }
  168. func (a *AlterClientQuotasRequest) requiredVersion() KafkaVersion {
  169. return V2_6_0_0
  170. }