Skip to content

Commit 7e314f9

Browse files
committed
adds StartOffset to the right struct
By mistake I added the field to the root level instead of adding to the blocks
1 parent 7728893 commit 7e314f9

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

produce_response.go

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ import (
55
"time"
66
)
77

8+
// Protocol, http://kafka.apache.org/protocol.html
9+
// v1
10+
// v2 = v3 = v4
11+
// v5 = v6 = v7
12+
// Produce Response (Version: 7) => [responses] throttle_time_ms
13+
// responses => topic [partition_responses]
14+
// topic => STRING
15+
// partition_responses => partition error_code base_offset log_append_time log_start_offset
16+
// partition => INT32
17+
// error_code => INT16
18+
// base_offset => INT64
19+
// log_append_time => INT64
20+
// log_start_offset => INT64
21+
// throttle_time_ms => INT32
22+
23+
// partition_responses in protocol
824
type ProduceResponseBlock struct {
9-
Err KError
10-
Offset int64
11-
// only provided if Version >= 2 and the broker is configured with `LogAppendTime`
12-
Timestamp time.Time
25+
Err KError // v0, error_code
26+
Offset int64 // v0, base_offset
27+
Timestamp time.Time // v2, log_append_time, and the broker is configured with `LogAppendTime`
28+
StartOffset int64 // v5, log_start_offset
1329
}
1430

1531
func (b *ProduceResponseBlock) decode(pd packetDecoder, version int16) (err error) {
@@ -32,6 +48,13 @@ func (b *ProduceResponseBlock) decode(pd packetDecoder, version int16) (err erro
3248
}
3349
}
3450

51+
if version >= 5 {
52+
b.StartOffset, err = pd.getInt64()
53+
if err != nil {
54+
return err
55+
}
56+
}
57+
3558
return nil
3659
}
3760

@@ -49,14 +72,17 @@ func (b *ProduceResponseBlock) encode(pe packetEncoder, version int16) (err erro
4972
pe.putInt64(timestamp)
5073
}
5174

75+
if version >= 5 {
76+
pe.putInt64(b.StartOffset)
77+
}
78+
5279
return nil
5380
}
5481

5582
type ProduceResponse struct {
56-
Blocks map[string]map[int32]*ProduceResponseBlock
83+
Blocks map[string]map[int32]*ProduceResponseBlock // v0, responses
5784
Version int16
58-
ThrottleTime time.Duration // only provided if Version >= 1
59-
StartOffset int64 // only provided if Version >= 5
85+
ThrottleTime time.Duration // v1, throttle_time_ms
6086
}
6187

6288
func (r *ProduceResponse) decode(pd packetDecoder, version int16) (err error) {
@@ -96,13 +122,6 @@ func (r *ProduceResponse) decode(pd packetDecoder, version int16) (err error) {
96122
}
97123
}
98124

99-
if version >= 5 {
100-
r.StartOffset, err = pd.getInt64()
101-
if err != nil {
102-
return err
103-
}
104-
}
105-
106125
if r.Version >= 1 {
107126
millis, err := pd.getInt32()
108127
if err != nil {
@@ -137,9 +156,6 @@ func (r *ProduceResponse) encode(pe packetEncoder) error {
137156
}
138157
}
139158
}
140-
if r.Version >= 5 {
141-
pe.putInt64(r.StartOffset)
142-
}
143159

144160
if r.Version >= 1 {
145161
pe.putInt32(int32(r.ThrottleTime / time.Millisecond))

0 commit comments

Comments
 (0)