alter_configs_request.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package sarama
  2. //AlterConfigsRequest is an alter config request type
  3. type AlterConfigsRequest struct {
  4. Resources []*AlterConfigsResource
  5. ValidateOnly bool
  6. }
  7. //AlterConfigsResource is an alter config resource type
  8. type AlterConfigsResource struct {
  9. Type ConfigResourceType
  10. Name string
  11. ConfigEntries map[string]*string
  12. }
  13. func (a *AlterConfigsRequest) encode(pe packetEncoder) error {
  14. if err := pe.putArrayLength(len(a.Resources)); err != nil {
  15. return err
  16. }
  17. for _, r := range a.Resources {
  18. if err := r.encode(pe); err != nil {
  19. return err
  20. }
  21. }
  22. pe.putBool(a.ValidateOnly)
  23. return nil
  24. }
  25. func (a *AlterConfigsRequest) decode(pd packetDecoder, version int16) error {
  26. resourceCount, err := pd.getArrayLength()
  27. if err != nil {
  28. return err
  29. }
  30. a.Resources = make([]*AlterConfigsResource, resourceCount)
  31. for i := range a.Resources {
  32. r := &AlterConfigsResource{}
  33. err = r.decode(pd, version)
  34. if err != nil {
  35. return err
  36. }
  37. a.Resources[i] = r
  38. }
  39. validateOnly, err := pd.getBool()
  40. if err != nil {
  41. return err
  42. }
  43. a.ValidateOnly = validateOnly
  44. return nil
  45. }
  46. func (a *AlterConfigsResource) encode(pe packetEncoder) error {
  47. pe.putInt8(int8(a.Type))
  48. if err := pe.putString(a.Name); err != nil {
  49. return err
  50. }
  51. if err := pe.putArrayLength(len(a.ConfigEntries)); err != nil {
  52. return err
  53. }
  54. for configKey, configValue := range a.ConfigEntries {
  55. if err := pe.putString(configKey); err != nil {
  56. return err
  57. }
  58. if err := pe.putNullableString(configValue); err != nil {
  59. return err
  60. }
  61. }
  62. return nil
  63. }
  64. func (a *AlterConfigsResource) decode(pd packetDecoder, version int16) error {
  65. t, err := pd.getInt8()
  66. if err != nil {
  67. return err
  68. }
  69. a.Type = ConfigResourceType(t)
  70. name, err := pd.getString()
  71. if err != nil {
  72. return err
  73. }
  74. a.Name = name
  75. n, err := pd.getArrayLength()
  76. if err != nil {
  77. return err
  78. }
  79. if n > 0 {
  80. a.ConfigEntries = make(map[string]*string, n)
  81. for i := 0; i < n; i++ {
  82. configKey, err := pd.getString()
  83. if err != nil {
  84. return err
  85. }
  86. if a.ConfigEntries[configKey], err = pd.getNullableString(); err != nil {
  87. return err
  88. }
  89. }
  90. }
  91. return err
  92. }
  93. func (a *AlterConfigsRequest) key() int16 {
  94. return 33
  95. }
  96. func (a *AlterConfigsRequest) version() int16 {
  97. return 0
  98. }
  99. func (a *AlterConfigsRequest) headerVersion() int16 {
  100. return 1
  101. }
  102. func (a *AlterConfigsRequest) requiredVersion() KafkaVersion {
  103. return V0_11_0_0
  104. }