Scott Baker | 2d89798 | 2019-09-24 11:50:08 -0700 | [diff] [blame^] | 1 | package sarama |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | type AlterConfigsResponse struct { |
| 6 | ThrottleTime time.Duration |
| 7 | Resources []*AlterConfigsResourceResponse |
| 8 | } |
| 9 | |
| 10 | type AlterConfigsResourceResponse struct { |
| 11 | ErrorCode int16 |
| 12 | ErrorMsg string |
| 13 | Type ConfigResourceType |
| 14 | Name string |
| 15 | } |
| 16 | |
| 17 | func (ct *AlterConfigsResponse) encode(pe packetEncoder) error { |
| 18 | pe.putInt32(int32(ct.ThrottleTime / time.Millisecond)) |
| 19 | |
| 20 | if err := pe.putArrayLength(len(ct.Resources)); err != nil { |
| 21 | return err |
| 22 | } |
| 23 | |
| 24 | for i := range ct.Resources { |
| 25 | pe.putInt16(ct.Resources[i].ErrorCode) |
| 26 | err := pe.putString(ct.Resources[i].ErrorMsg) |
| 27 | if err != nil { |
| 28 | return nil |
| 29 | } |
| 30 | pe.putInt8(int8(ct.Resources[i].Type)) |
| 31 | err = pe.putString(ct.Resources[i].Name) |
| 32 | if err != nil { |
| 33 | return nil |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return nil |
| 38 | } |
| 39 | |
| 40 | func (acr *AlterConfigsResponse) decode(pd packetDecoder, version int16) error { |
| 41 | throttleTime, err := pd.getInt32() |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | acr.ThrottleTime = time.Duration(throttleTime) * time.Millisecond |
| 46 | |
| 47 | responseCount, err := pd.getArrayLength() |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | |
| 52 | acr.Resources = make([]*AlterConfigsResourceResponse, responseCount) |
| 53 | |
| 54 | for i := range acr.Resources { |
| 55 | acr.Resources[i] = new(AlterConfigsResourceResponse) |
| 56 | |
| 57 | errCode, err := pd.getInt16() |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | acr.Resources[i].ErrorCode = errCode |
| 62 | |
| 63 | e, err := pd.getString() |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | acr.Resources[i].ErrorMsg = e |
| 68 | |
| 69 | t, err := pd.getInt8() |
| 70 | if err != nil { |
| 71 | return err |
| 72 | } |
| 73 | acr.Resources[i].Type = ConfigResourceType(t) |
| 74 | |
| 75 | name, err := pd.getString() |
| 76 | if err != nil { |
| 77 | return err |
| 78 | } |
| 79 | acr.Resources[i].Name = name |
| 80 | } |
| 81 | |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | func (r *AlterConfigsResponse) key() int16 { |
| 86 | return 32 |
| 87 | } |
| 88 | |
| 89 | func (r *AlterConfigsResponse) version() int16 { |
| 90 | return 0 |
| 91 | } |
| 92 | |
| 93 | func (r *AlterConfigsResponse) requiredVersion() KafkaVersion { |
| 94 | return V0_11_0_0 |
| 95 | } |