describe_configs_response.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package sarama
  2. import "time"
  3. type DescribeConfigsResponse struct {
  4. ThrottleTime time.Duration
  5. Resources []*ResourceResponse
  6. }
  7. type ResourceResponse struct {
  8. ErrorCode int16
  9. ErrorMsg string
  10. Type ConfigResourceType
  11. Name string
  12. Configs []*ConfigEntry
  13. }
  14. type ConfigEntry struct {
  15. Name string
  16. Value string
  17. ReadOnly bool
  18. Default bool
  19. Sensitive bool
  20. }
  21. func (r *DescribeConfigsResponse) encode(pe packetEncoder) (err error) {
  22. pe.putInt32(int32(r.ThrottleTime / time.Millisecond))
  23. if err = pe.putArrayLength(len(r.Resources)); err != nil {
  24. return err
  25. }
  26. for _, c := range r.Resources {
  27. if err = c.encode(pe); err != nil {
  28. return err
  29. }
  30. }
  31. return nil
  32. }
  33. func (r *DescribeConfigsResponse) decode(pd packetDecoder, version int16) (err error) {
  34. throttleTime, err := pd.getInt32()
  35. if err != nil {
  36. return err
  37. }
  38. r.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
  39. n, err := pd.getArrayLength()
  40. if err != nil {
  41. return err
  42. }
  43. r.Resources = make([]*ResourceResponse, n)
  44. for i := 0; i < n; i++ {
  45. rr := &ResourceResponse{}
  46. if err := rr.decode(pd, version); err != nil {
  47. return err
  48. }
  49. r.Resources[i] = rr
  50. }
  51. return nil
  52. }
  53. func (r *DescribeConfigsResponse) key() int16 {
  54. return 32
  55. }
  56. func (r *DescribeConfigsResponse) version() int16 {
  57. return 0
  58. }
  59. func (r *DescribeConfigsResponse) requiredVersion() KafkaVersion {
  60. return V0_11_0_0
  61. }
  62. func (r *ResourceResponse) encode(pe packetEncoder) (err error) {
  63. pe.putInt16(r.ErrorCode)
  64. if err = pe.putString(r.ErrorMsg); err != nil {
  65. return err
  66. }
  67. pe.putInt8(int8(r.Type))
  68. if err = pe.putString(r.Name); err != nil {
  69. return err
  70. }
  71. if err = pe.putArrayLength(len(r.Configs)); err != nil {
  72. return err
  73. }
  74. for _, c := range r.Configs {
  75. if err = c.encode(pe); err != nil {
  76. return err
  77. }
  78. }
  79. return nil
  80. }
  81. func (r *ResourceResponse) decode(pd packetDecoder, version int16) (err error) {
  82. ec, err := pd.getInt16()
  83. if err != nil {
  84. return err
  85. }
  86. r.ErrorCode = ec
  87. em, err := pd.getString()
  88. if err != nil {
  89. return err
  90. }
  91. r.ErrorMsg = em
  92. t, err := pd.getInt8()
  93. if err != nil {
  94. return err
  95. }
  96. r.Type = ConfigResourceType(t)
  97. name, err := pd.getString()
  98. if err != nil {
  99. return err
  100. }
  101. r.Name = name
  102. n, err := pd.getArrayLength()
  103. if err != nil {
  104. return err
  105. }
  106. r.Configs = make([]*ConfigEntry, n)
  107. for i := 0; i < n; i++ {
  108. c := &ConfigEntry{}
  109. if err := c.decode(pd, version); err != nil {
  110. return err
  111. }
  112. r.Configs[i] = c
  113. }
  114. return nil
  115. }
  116. func (r *ConfigEntry) encode(pe packetEncoder) (err error) {
  117. if err = pe.putString(r.Name); err != nil {
  118. return err
  119. }
  120. if err = pe.putString(r.Value); err != nil {
  121. return err
  122. }
  123. pe.putBool(r.ReadOnly)
  124. pe.putBool(r.Default)
  125. pe.putBool(r.Sensitive)
  126. return nil
  127. }
  128. func (r *ConfigEntry) decode(pd packetDecoder, version int16) (err error) {
  129. name, err := pd.getString()
  130. if err != nil {
  131. return err
  132. }
  133. r.Name = name
  134. value, err := pd.getString()
  135. if err != nil {
  136. return err
  137. }
  138. r.Value = value
  139. read, err := pd.getBool()
  140. if err != nil {
  141. return err
  142. }
  143. r.ReadOnly = read
  144. de, err := pd.getBool()
  145. if err != nil {
  146. return err
  147. }
  148. r.Default = de
  149. sensitive, err := pd.getBool()
  150. if err != nil {
  151. return err
  152. }
  153. r.Sensitive = sensitive
  154. return nil
  155. }