alter_configs_request.go 2.2 KB

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