| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 1 | package sarama |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | ) |
| 6 | |
| 7 | type DeleteOffsetsResponse struct { |
| 8 | Version int16 |
| 9 | // The top-level error code, or 0 if there was no error. |
| 10 | ErrorCode KError |
| 11 | ThrottleTime time.Duration |
| 12 | // The responses for each partition of the topics. |
| 13 | Errors map[string]map[int32]KError |
| 14 | } |
| 15 | |
| 16 | func (r *DeleteOffsetsResponse) setVersion(v int16) { |
| 17 | r.Version = v |
| 18 | } |
| 19 | |
| 20 | func (r *DeleteOffsetsResponse) AddError(topic string, partition int32, errorCode KError) { |
| 21 | if r.Errors == nil { |
| 22 | r.Errors = make(map[string]map[int32]KError) |
| 23 | } |
| 24 | partitions := r.Errors[topic] |
| 25 | if partitions == nil { |
| 26 | partitions = make(map[int32]KError) |
| 27 | r.Errors[topic] = partitions |
| 28 | } |
| 29 | partitions[partition] = errorCode |
| 30 | } |
| 31 | |
| 32 | func (r *DeleteOffsetsResponse) encode(pe packetEncoder) error { |
| 33 | pe.putKError(r.ErrorCode) |
| 34 | pe.putDurationMs(r.ThrottleTime) |
| 35 | |
| 36 | if err := pe.putArrayLength(len(r.Errors)); err != nil { |
| 37 | return err |
| 38 | } |
| 39 | for topic, partitions := range r.Errors { |
| 40 | if err := pe.putString(topic); err != nil { |
| 41 | return err |
| 42 | } |
| 43 | if err := pe.putArrayLength(len(partitions)); err != nil { |
| 44 | return err |
| 45 | } |
| 46 | for partition, errorCode := range partitions { |
| 47 | pe.putInt32(partition) |
| 48 | pe.putKError(errorCode) |
| 49 | } |
| 50 | } |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | func (r *DeleteOffsetsResponse) decode(pd packetDecoder, version int16) (err error) { |
| 55 | r.ErrorCode, err = pd.getKError() |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | if r.ThrottleTime, err = pd.getDurationMs(); err != nil { |
| 61 | return err |
| 62 | } |
| 63 | |
| 64 | numTopics, err := pd.getArrayLength() |
| 65 | if err != nil || numTopics == 0 { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | r.Errors = make(map[string]map[int32]KError, numTopics) |
| 70 | for i := 0; i < numTopics; i++ { |
| 71 | name, err := pd.getString() |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | |
| 76 | numErrors, err := pd.getArrayLength() |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | |
| 81 | r.Errors[name] = make(map[int32]KError, numErrors) |
| 82 | |
| 83 | for j := 0; j < numErrors; j++ { |
| 84 | id, err := pd.getInt32() |
| 85 | if err != nil { |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | r.Errors[name][id], err = pd.getKError() |
| 90 | if err != nil { |
| 91 | return err |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return nil |
| 97 | } |
| 98 | |
| 99 | func (r *DeleteOffsetsResponse) key() int16 { |
| 100 | return apiKeyOffsetDelete |
| 101 | } |
| 102 | |
| 103 | func (r *DeleteOffsetsResponse) version() int16 { |
| 104 | return r.Version |
| 105 | } |
| 106 | |
| 107 | func (r *DeleteOffsetsResponse) headerVersion() int16 { |
| 108 | return 0 |
| 109 | } |
| 110 | |
| 111 | func (r *DeleteOffsetsResponse) isValidVersion() bool { |
| 112 | return r.Version == 0 |
| 113 | } |
| 114 | |
| 115 | func (r *DeleteOffsetsResponse) requiredVersion() KafkaVersion { |
| 116 | return V2_4_0_0 |
| 117 | } |
| 118 | |
| 119 | func (r *DeleteOffsetsResponse) throttleTime() time.Duration { |
| 120 | return r.ThrottleTime |
| 121 | } |