describe_configs_request.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package sarama
  2. type ConfigResource struct {
  3. Type ConfigResourceType
  4. Name string
  5. ConfigNames []string
  6. }
  7. type DescribeConfigsRequest struct {
  8. Resources []*ConfigResource
  9. }
  10. func (r *DescribeConfigsRequest) encode(pe packetEncoder) error {
  11. if err := pe.putArrayLength(len(r.Resources)); err != nil {
  12. return err
  13. }
  14. for _, c := range r.Resources {
  15. pe.putInt8(int8(c.Type))
  16. if err := pe.putString(c.Name); err != nil {
  17. return err
  18. }
  19. if len(c.ConfigNames) == 0 {
  20. pe.putInt32(-1)
  21. continue
  22. }
  23. if err := pe.putStringArray(c.ConfigNames); err != nil {
  24. return err
  25. }
  26. }
  27. return nil
  28. }
  29. func (r *DescribeConfigsRequest) decode(pd packetDecoder, version int16) (err error) {
  30. n, err := pd.getArrayLength()
  31. if err != nil {
  32. return err
  33. }
  34. r.Resources = make([]*ConfigResource, n)
  35. for i := 0; i < n; i++ {
  36. r.Resources[i] = &ConfigResource{}
  37. t, err := pd.getInt8()
  38. if err != nil {
  39. return err
  40. }
  41. r.Resources[i].Type = ConfigResourceType(t)
  42. name, err := pd.getString()
  43. if err != nil {
  44. return err
  45. }
  46. r.Resources[i].Name = name
  47. confLength, err := pd.getArrayLength()
  48. if err != nil {
  49. return err
  50. }
  51. if confLength == -1 {
  52. continue
  53. }
  54. cfnames := make([]string, confLength)
  55. for i := 0; i < confLength; i++ {
  56. s, err := pd.getString()
  57. if err != nil {
  58. return err
  59. }
  60. cfnames[i] = s
  61. }
  62. r.Resources[i].ConfigNames = cfnames
  63. }
  64. return nil
  65. }
  66. func (r *DescribeConfigsRequest) key() int16 {
  67. return 32
  68. }
  69. func (r *DescribeConfigsRequest) version() int16 {
  70. return 0
  71. }
  72. func (r *DescribeConfigsRequest) requiredVersion() KafkaVersion {
  73. return V0_11_0_0
  74. }