khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 1 | package sarama |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | type CreatePartitionsResponse struct { |
| 6 | ThrottleTime time.Duration |
| 7 | TopicPartitionErrors map[string]*TopicPartitionError |
| 8 | } |
| 9 | |
| 10 | func (c *CreatePartitionsResponse) encode(pe packetEncoder) error { |
| 11 | pe.putInt32(int32(c.ThrottleTime / time.Millisecond)) |
| 12 | if err := pe.putArrayLength(len(c.TopicPartitionErrors)); err != nil { |
| 13 | return err |
| 14 | } |
| 15 | |
| 16 | for topic, partitionError := range c.TopicPartitionErrors { |
| 17 | if err := pe.putString(topic); err != nil { |
| 18 | return err |
| 19 | } |
| 20 | if err := partitionError.encode(pe); err != nil { |
| 21 | return err |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | return nil |
| 26 | } |
| 27 | |
| 28 | func (c *CreatePartitionsResponse) decode(pd packetDecoder, version int16) (err error) { |
| 29 | throttleTime, err := pd.getInt32() |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | c.ThrottleTime = time.Duration(throttleTime) * time.Millisecond |
| 34 | |
| 35 | n, err := pd.getArrayLength() |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | c.TopicPartitionErrors = make(map[string]*TopicPartitionError, n) |
| 41 | for i := 0; i < n; i++ { |
| 42 | topic, err := pd.getString() |
| 43 | if err != nil { |
| 44 | return err |
| 45 | } |
| 46 | c.TopicPartitionErrors[topic] = new(TopicPartitionError) |
| 47 | if err := c.TopicPartitionErrors[topic].decode(pd, version); err != nil { |
| 48 | return err |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return nil |
| 53 | } |
| 54 | |
| 55 | func (r *CreatePartitionsResponse) key() int16 { |
| 56 | return 37 |
| 57 | } |
| 58 | |
| 59 | func (r *CreatePartitionsResponse) version() int16 { |
| 60 | return 0 |
| 61 | } |
| 62 | |
| 63 | func (r *CreatePartitionsResponse) requiredVersion() KafkaVersion { |
| 64 | return V1_0_0_0 |
| 65 | } |
| 66 | |
| 67 | type TopicPartitionError struct { |
| 68 | Err KError |
| 69 | ErrMsg *string |
| 70 | } |
| 71 | |
| 72 | func (t *TopicPartitionError) encode(pe packetEncoder) error { |
| 73 | pe.putInt16(int16(t.Err)) |
| 74 | |
| 75 | if err := pe.putNullableString(t.ErrMsg); err != nil { |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | return nil |
| 80 | } |
| 81 | |
| 82 | func (t *TopicPartitionError) decode(pd packetDecoder, version int16) (err error) { |
| 83 | kerr, err := pd.getInt16() |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | t.Err = KError(kerr) |
| 88 | |
| 89 | if t.ErrMsg, err = pd.getNullableString(); err != nil { |
| 90 | return err |
| 91 | } |
| 92 | |
| 93 | return nil |
| 94 | } |