Skip to content

Commit 695bfab

Browse files
committed
refactor: replace Record.Encode with EncodeFull for accurate encoding
1 parent ce4015e commit 695bfab

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

protocol/api/record_batch.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (rb RecordBatch) Encode(pe *encoder.Encoder) {
5858
for i, record := range rb.Records {
5959
record.OffsetDelta = int32(i) // Offset Deltas are consecutive numerals from 0 to N-1
6060
// We can set them programmatically as we know the order of the records
61-
record.Encode(pe)
61+
record.EncodeFull(pe)
6262
}
6363

6464
batchLength := pe.Offset() - 12 - startOffset // 8 bytes for BaseOffset & 4 bytes for BatchLength
@@ -219,11 +219,13 @@ type Record struct {
219219
Headers []RecordHeader
220220
}
221221

222-
func (r Record) Encode(pe *encoder.Encoder) {
223-
pe.PutVarint(int64(utils.GetEncodedLength(r))) // Length placeholder
222+
func (r Record) EncodeFull(pe *encoder.Encoder) {
223+
pe.PutVarint(int64(utils.GetEncodedLength(r))) // Length
224224
// As this is variable length, we can't use placeholders and update later reliably.
225-
// We need to have a value, close to the actual value, such that it takes the same space
226-
// This is an approx value, the actual value will be computed at the end
225+
r.Encode(pe)
226+
}
227+
228+
func (r Record) Encode(pe *encoder.Encoder) {
227229
pe.PutInt8(r.Attributes)
228230
pe.PutVarint(r.TimestampDelta)
229231
pe.PutVarint(int64(r.OffsetDelta))

0 commit comments

Comments
 (0)