David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame] | 1 | package sarama |
| 2 | |
| 3 | type alterPartitionReassignmentsErrorBlock struct { |
| 4 | errorCode KError |
| 5 | errorMessage *string |
| 6 | } |
| 7 | |
| 8 | func (b *alterPartitionReassignmentsErrorBlock) encode(pe packetEncoder) error { |
| 9 | pe.putInt16(int16(b.errorCode)) |
| 10 | if err := pe.putNullableCompactString(b.errorMessage); err != nil { |
| 11 | return err |
| 12 | } |
| 13 | pe.putEmptyTaggedFieldArray() |
| 14 | |
| 15 | return nil |
| 16 | } |
| 17 | |
| 18 | func (b *alterPartitionReassignmentsErrorBlock) decode(pd packetDecoder) (err error) { |
| 19 | errorCode, err := pd.getInt16() |
| 20 | if err != nil { |
| 21 | return err |
| 22 | } |
| 23 | b.errorCode = KError(errorCode) |
| 24 | b.errorMessage, err = pd.getCompactNullableString() |
| 25 | |
| 26 | if _, err := pd.getEmptyTaggedFieldArray(); err != nil { |
| 27 | return err |
| 28 | } |
| 29 | return err |
| 30 | } |
| 31 | |
| 32 | type AlterPartitionReassignmentsResponse struct { |
| 33 | Version int16 |
| 34 | ThrottleTimeMs int32 |
| 35 | ErrorCode KError |
| 36 | ErrorMessage *string |
| 37 | Errors map[string]map[int32]*alterPartitionReassignmentsErrorBlock |
| 38 | } |
| 39 | |
| 40 | func (r *AlterPartitionReassignmentsResponse) AddError(topic string, partition int32, kerror KError, message *string) { |
| 41 | if r.Errors == nil { |
| 42 | r.Errors = make(map[string]map[int32]*alterPartitionReassignmentsErrorBlock) |
| 43 | } |
| 44 | partitions := r.Errors[topic] |
| 45 | if partitions == nil { |
| 46 | partitions = make(map[int32]*alterPartitionReassignmentsErrorBlock) |
| 47 | r.Errors[topic] = partitions |
| 48 | } |
| 49 | |
| 50 | partitions[partition] = &alterPartitionReassignmentsErrorBlock{errorCode: kerror, errorMessage: message} |
| 51 | } |
| 52 | |
| 53 | func (r *AlterPartitionReassignmentsResponse) encode(pe packetEncoder) error { |
| 54 | pe.putInt32(r.ThrottleTimeMs) |
| 55 | pe.putInt16(int16(r.ErrorCode)) |
| 56 | if err := pe.putNullableCompactString(r.ErrorMessage); err != nil { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | pe.putCompactArrayLength(len(r.Errors)) |
| 61 | for topic, partitions := range r.Errors { |
| 62 | if err := pe.putCompactString(topic); err != nil { |
| 63 | return err |
| 64 | } |
| 65 | pe.putCompactArrayLength(len(partitions)) |
| 66 | for partition, block := range partitions { |
| 67 | pe.putInt32(partition) |
| 68 | |
| 69 | if err := block.encode(pe); err != nil { |
| 70 | return err |
| 71 | } |
| 72 | } |
| 73 | pe.putEmptyTaggedFieldArray() |
| 74 | } |
| 75 | |
| 76 | pe.putEmptyTaggedFieldArray() |
| 77 | return nil |
| 78 | } |
| 79 | |
| 80 | func (r *AlterPartitionReassignmentsResponse) decode(pd packetDecoder, version int16) (err error) { |
| 81 | r.Version = version |
| 82 | |
| 83 | if r.ThrottleTimeMs, err = pd.getInt32(); err != nil { |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | kerr, err := pd.getInt16() |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | |
| 92 | r.ErrorCode = KError(kerr) |
| 93 | |
| 94 | if r.ErrorMessage, err = pd.getCompactNullableString(); err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | numTopics, err := pd.getCompactArrayLength() |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | |
| 103 | if numTopics > 0 { |
| 104 | r.Errors = make(map[string]map[int32]*alterPartitionReassignmentsErrorBlock, numTopics) |
| 105 | for i := 0; i < numTopics; i++ { |
| 106 | topic, err := pd.getCompactString() |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | |
| 111 | ongoingPartitionReassignments, err := pd.getCompactArrayLength() |
| 112 | if err != nil { |
| 113 | return err |
| 114 | } |
| 115 | |
| 116 | r.Errors[topic] = make(map[int32]*alterPartitionReassignmentsErrorBlock, ongoingPartitionReassignments) |
| 117 | |
| 118 | for j := 0; j < ongoingPartitionReassignments; j++ { |
| 119 | partition, err := pd.getInt32() |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | block := &alterPartitionReassignmentsErrorBlock{} |
| 124 | if err := block.decode(pd); err != nil { |
| 125 | return err |
| 126 | } |
| 127 | |
| 128 | r.Errors[topic][partition] = block |
| 129 | } |
| 130 | if _, err = pd.getEmptyTaggedFieldArray(); err != nil { |
| 131 | return err |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if _, err = pd.getEmptyTaggedFieldArray(); err != nil { |
| 137 | return err |
| 138 | } |
| 139 | |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | func (r *AlterPartitionReassignmentsResponse) key() int16 { |
| 144 | return 45 |
| 145 | } |
| 146 | |
| 147 | func (r *AlterPartitionReassignmentsResponse) version() int16 { |
| 148 | return r.Version |
| 149 | } |
| 150 | |
| 151 | func (r *AlterPartitionReassignmentsResponse) headerVersion() int16 { |
| 152 | return 1 |
| 153 | } |
| 154 | |
| 155 | func (r *AlterPartitionReassignmentsResponse) requiredVersion() KafkaVersion { |
| 156 | return V2_4_0_0 |
| 157 | } |