Scott Baker | 2d89798 | 2019-09-24 11:50:08 -0700 | [diff] [blame^] | 1 | package sarama |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | ) |
| 6 | |
| 7 | type DeleteGroupsResponse struct { |
| 8 | ThrottleTime time.Duration |
| 9 | GroupErrorCodes map[string]KError |
| 10 | } |
| 11 | |
| 12 | func (r *DeleteGroupsResponse) encode(pe packetEncoder) error { |
| 13 | pe.putInt32(int32(r.ThrottleTime / time.Millisecond)) |
| 14 | |
| 15 | if err := pe.putArrayLength(len(r.GroupErrorCodes)); err != nil { |
| 16 | return err |
| 17 | } |
| 18 | for groupID, errorCode := range r.GroupErrorCodes { |
| 19 | if err := pe.putString(groupID); err != nil { |
| 20 | return err |
| 21 | } |
| 22 | pe.putInt16(int16(errorCode)) |
| 23 | } |
| 24 | |
| 25 | return nil |
| 26 | } |
| 27 | |
| 28 | func (r *DeleteGroupsResponse) decode(pd packetDecoder, version int16) error { |
| 29 | throttleTime, err := pd.getInt32() |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | r.ThrottleTime = time.Duration(throttleTime) * time.Millisecond |
| 34 | |
| 35 | n, err := pd.getArrayLength() |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | if n == 0 { |
| 40 | return nil |
| 41 | } |
| 42 | |
| 43 | r.GroupErrorCodes = make(map[string]KError, n) |
| 44 | for i := 0; i < n; i++ { |
| 45 | groupID, err := pd.getString() |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | errorCode, err := pd.getInt16() |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | |
| 54 | r.GroupErrorCodes[groupID] = KError(errorCode) |
| 55 | } |
| 56 | |
| 57 | return nil |
| 58 | } |
| 59 | |
| 60 | func (r *DeleteGroupsResponse) key() int16 { |
| 61 | return 42 |
| 62 | } |
| 63 | |
| 64 | func (r *DeleteGroupsResponse) version() int16 { |
| 65 | return 0 |
| 66 | } |
| 67 | |
| 68 | func (r *DeleteGroupsResponse) requiredVersion() KafkaVersion { |
| 69 | return V1_1_0_0 |
| 70 | } |