NewOffsetCommitRequest creates an OffsetCommitRequest with the highest version conf.Version allows and the retention time from conf.Consumer.Offsets.Retention.
(conf *Config, group string)
| 87 | // version conf.Version allows and the retention time from |
| 88 | // conf.Consumer.Offsets.Retention. |
| 89 | func NewOffsetCommitRequest(conf *Config, group string) *OffsetCommitRequest { |
| 90 | request := &OffsetCommitRequest{ |
| 91 | ConsumerGroup: group, |
| 92 | ConsumerGroupGeneration: GroupGenerationUndefined, |
| 93 | } |
| 94 | |
| 95 | if conf.Version.IsAtLeast(V2_4_0_0) { |
| 96 | // Version 8 is the first flexible version. |
| 97 | request.Version = 8 |
| 98 | } else if conf.Version.IsAtLeast(V2_3_0_0) { |
| 99 | // Version 7 adds GroupInstanceId. |
| 100 | request.Version = 7 |
| 101 | } else if conf.Version.IsAtLeast(V2_1_0_0) { |
| 102 | // Version 6 adds committed leader epoch (version 5 removes retention time). |
| 103 | request.Version = 6 |
| 104 | } else if conf.Version.IsAtLeast(V2_0_0_0) { |
| 105 | // Version 4 is the same as version 2. |
| 106 | request.Version = 4 |
| 107 | } else if conf.Version.IsAtLeast(V0_11_0_0) { |
| 108 | // Version 3 is the same as version 2. |
| 109 | request.Version = 3 |
| 110 | } else if conf.Version.IsAtLeast(V0_9_0_0) { |
| 111 | // Version 2 adds retention time and removes the commit timestamp from version 1. |
| 112 | request.Version = 2 |
| 113 | } else { |
| 114 | // Version 1 adds commit timestamp and group membership. |
| 115 | request.Version = 1 |
| 116 | } |
| 117 | |
| 118 | // set for every version from 2 up: the broker can negotiate v5+ down to |
| 119 | // v2-v4, which send RetentionTime (otherwise 0 there expires the offsets |
| 120 | // straight away) |
| 121 | if request.Version >= 2 { |
| 122 | request.RetentionTime = -1 |
| 123 | if conf.Consumer.Offsets.Retention > 0 { |
| 124 | request.RetentionTime = conf.Consumer.Offsets.Retention.Milliseconds() |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return request |
| 129 | } |
| 130 | |
| 131 | func (r *OffsetCommitRequest) encode(pe packetEncoder) error { |
| 132 | if r.Version < 0 || r.Version > 8 { |
no test coverage detected