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