blob: 12ce78857bc53f2c2482bae03b8e137d74c48c60 [file] [log] [blame]
khenaidooac637102019-01-14 15:44:34 -05001package sarama
2
Scott Baker8461e152019-10-01 14:44:30 -07003import (
4 "fmt"
5 "time"
6)
khenaidooac637102019-01-14 15:44:34 -05007
8type CreatePartitionsResponse struct {
9 ThrottleTime time.Duration
10 TopicPartitionErrors map[string]*TopicPartitionError
11}
12
13func (c *CreatePartitionsResponse) encode(pe packetEncoder) error {
14 pe.putInt32(int32(c.ThrottleTime / time.Millisecond))
15 if err := pe.putArrayLength(len(c.TopicPartitionErrors)); err != nil {
16 return err
17 }
18
19 for topic, partitionError := range c.TopicPartitionErrors {
20 if err := pe.putString(topic); err != nil {
21 return err
22 }
23 if err := partitionError.encode(pe); err != nil {
24 return err
25 }
26 }
27
28 return nil
29}
30
31func (c *CreatePartitionsResponse) decode(pd packetDecoder, version int16) (err error) {
32 throttleTime, err := pd.getInt32()
33 if err != nil {
34 return err
35 }
36 c.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
37
38 n, err := pd.getArrayLength()
39 if err != nil {
40 return err
41 }
42
43 c.TopicPartitionErrors = make(map[string]*TopicPartitionError, n)
44 for i := 0; i < n; i++ {
45 topic, err := pd.getString()
46 if err != nil {
47 return err
48 }
49 c.TopicPartitionErrors[topic] = new(TopicPartitionError)
50 if err := c.TopicPartitionErrors[topic].decode(pd, version); err != nil {
51 return err
52 }
53 }
54
55 return nil
56}
57
58func (r *CreatePartitionsResponse) key() int16 {
59 return 37
60}
61
62func (r *CreatePartitionsResponse) version() int16 {
63 return 0
64}
65
khenaidood948f772021-08-11 17:49:24 -040066func (r *CreatePartitionsResponse) headerVersion() int16 {
67 return 0
68}
69
khenaidooac637102019-01-14 15:44:34 -050070func (r *CreatePartitionsResponse) requiredVersion() KafkaVersion {
71 return V1_0_0_0
72}
73
74type TopicPartitionError struct {
75 Err KError
76 ErrMsg *string
77}
78
Scott Baker8461e152019-10-01 14:44:30 -070079func (t *TopicPartitionError) Error() string {
80 text := t.Err.Error()
81 if t.ErrMsg != nil {
82 text = fmt.Sprintf("%s - %s", text, *t.ErrMsg)
83 }
84 return text
85}
86
khenaidooac637102019-01-14 15:44:34 -050087func (t *TopicPartitionError) encode(pe packetEncoder) error {
88 pe.putInt16(int16(t.Err))
89
90 if err := pe.putNullableString(t.ErrMsg); err != nil {
91 return err
92 }
93
94 return nil
95}
96
97func (t *TopicPartitionError) decode(pd packetDecoder, version int16) (err error) {
98 kerr, err := pd.getInt16()
99 if err != nil {
100 return err
101 }
102 t.Err = KError(kerr)
103
104 if t.ErrMsg, err = pd.getNullableString(); err != nil {
105 return err
106 }
107
108 return nil
109}