William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 1 | package sarama |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | ) |
| 6 | |
| 7 | type TxnOffsetCommitResponse struct { |
| 8 | ThrottleTime time.Duration |
| 9 | Topics map[string][]*PartitionError |
| 10 | } |
| 11 | |
| 12 | func (t *TxnOffsetCommitResponse) encode(pe packetEncoder) error { |
| 13 | pe.putInt32(int32(t.ThrottleTime / time.Millisecond)) |
| 14 | if err := pe.putArrayLength(len(t.Topics)); err != nil { |
| 15 | return err |
| 16 | } |
| 17 | |
| 18 | for topic, e := range t.Topics { |
| 19 | if err := pe.putString(topic); err != nil { |
| 20 | return err |
| 21 | } |
| 22 | if err := pe.putArrayLength(len(e)); err != nil { |
| 23 | return err |
| 24 | } |
| 25 | for _, partitionError := range e { |
| 26 | if err := partitionError.encode(pe); err != nil { |
| 27 | return err |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return nil |
| 33 | } |
| 34 | |
| 35 | func (t *TxnOffsetCommitResponse) decode(pd packetDecoder, version int16) (err error) { |
| 36 | throttleTime, err := pd.getInt32() |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | t.ThrottleTime = time.Duration(throttleTime) * time.Millisecond |
| 41 | |
| 42 | n, err := pd.getArrayLength() |
| 43 | if err != nil { |
| 44 | return err |
| 45 | } |
| 46 | |
| 47 | t.Topics = make(map[string][]*PartitionError) |
| 48 | |
| 49 | for i := 0; i < n; i++ { |
| 50 | topic, err := pd.getString() |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | m, err := pd.getArrayLength() |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | t.Topics[topic] = make([]*PartitionError, m) |
| 61 | |
| 62 | for j := 0; j < m; j++ { |
| 63 | t.Topics[topic][j] = new(PartitionError) |
| 64 | if err := t.Topics[topic][j].decode(pd, version); err != nil { |
| 65 | return err |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | func (a *TxnOffsetCommitResponse) key() int16 { |
| 74 | return 28 |
| 75 | } |
| 76 | |
| 77 | func (a *TxnOffsetCommitResponse) version() int16 { |
| 78 | return 0 |
| 79 | } |
| 80 | |
| 81 | func (a *TxnOffsetCommitResponse) requiredVersion() KafkaVersion { |
| 82 | return V0_11_0_0 |
| 83 | } |