blob: 64180b19201ed1d9e8175b5644c90ee81bb1424c [file] [log] [blame]
Abhay Kumara2ae5992025-11-10 14:02:24 +00001package sarama
2
3import (
4 "time"
5)
6
7type 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
16func (r *DeleteOffsetsResponse) setVersion(v int16) {
17 r.Version = v
18}
19
20func (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
32func (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
54func (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
99func (r *DeleteOffsetsResponse) key() int16 {
100 return apiKeyOffsetDelete
101}
102
103func (r *DeleteOffsetsResponse) version() int16 {
104 return r.Version
105}
106
107func (r *DeleteOffsetsResponse) headerVersion() int16 {
108 return 0
109}
110
111func (r *DeleteOffsetsResponse) isValidVersion() bool {
112 return r.Version == 0
113}
114
115func (r *DeleteOffsetsResponse) requiredVersion() KafkaVersion {
116 return V2_4_0_0
117}
118
119func (r *DeleteOffsetsResponse) throttleTime() time.Duration {
120 return r.ThrottleTime
121}