alter_configs_response.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package sarama
  2. import "time"
  3. //AlterConfigsResponse is a reponse type for alter config
  4. type AlterConfigsResponse struct {
  5. ThrottleTime time.Duration
  6. Resources []*AlterConfigsResourceResponse
  7. }
  8. //AlterConfigsResourceResponse is a reponse type for alter config resource
  9. type AlterConfigsResourceResponse struct {
  10. ErrorCode int16
  11. ErrorMsg string
  12. Type ConfigResourceType
  13. Name string
  14. }
  15. func (a *AlterConfigsResponse) encode(pe packetEncoder) error {
  16. pe.putInt32(int32(a.ThrottleTime / time.Millisecond))
  17. if err := pe.putArrayLength(len(a.Resources)); err != nil {
  18. return err
  19. }
  20. for i := range a.Resources {
  21. pe.putInt16(a.Resources[i].ErrorCode)
  22. err := pe.putString(a.Resources[i].ErrorMsg)
  23. if err != nil {
  24. return nil
  25. }
  26. pe.putInt8(int8(a.Resources[i].Type))
  27. err = pe.putString(a.Resources[i].Name)
  28. if err != nil {
  29. return nil
  30. }
  31. }
  32. return nil
  33. }
  34. func (a *AlterConfigsResponse) decode(pd packetDecoder, version int16) error {
  35. throttleTime, err := pd.getInt32()
  36. if err != nil {
  37. return err
  38. }
  39. a.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
  40. responseCount, err := pd.getArrayLength()
  41. if err != nil {
  42. return err
  43. }
  44. a.Resources = make([]*AlterConfigsResourceResponse, responseCount)
  45. for i := range a.Resources {
  46. a.Resources[i] = new(AlterConfigsResourceResponse)
  47. errCode, err := pd.getInt16()
  48. if err != nil {
  49. return err
  50. }
  51. a.Resources[i].ErrorCode = errCode
  52. e, err := pd.getString()
  53. if err != nil {
  54. return err
  55. }
  56. a.Resources[i].ErrorMsg = e
  57. t, err := pd.getInt8()
  58. if err != nil {
  59. return err
  60. }
  61. a.Resources[i].Type = ConfigResourceType(t)
  62. name, err := pd.getString()
  63. if err != nil {
  64. return err
  65. }
  66. a.Resources[i].Name = name
  67. }
  68. return nil
  69. }
  70. func (a *AlterConfigsResponse) key() int16 {
  71. return 32
  72. }
  73. func (a *AlterConfigsResponse) version() int16 {
  74. return 0
  75. }
  76. func (a *AlterConfigsResponse) requiredVersion() KafkaVersion {
  77. return V0_11_0_0
  78. }