describe_configs_request.go 2.0 KB

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