Skip to content

Commit 8376686

Browse files
committed
Fixed serialisation bug by avoiding using the raw buffer
The raw buffer is sometimes expanded for performance reasons, which leaves the buffer with additional zeros. This fix just returns the written bytes of the PipeBuffer, instead of including the extra padding.
1 parent 46ccf1d commit 8376686

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/event.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ format. The format follows the following rule (in bytes)
2929
#4 N..N+8 UInt32 masked_CRC of #3
3030
"""
3131
function write_event(out::IO, event::Event)
32-
data = PipeBuffer();
33-
encode(ProtoEncoder(data), event)
32+
event_bytes = serialize_proto(event)
3433

3534
#header
36-
header = collect(reinterpret(UInt8, [data.size]))
35+
header = collect(reinterpret(UInt8, [length(event_bytes)]))
3736
crc_header = reinterpret(UInt8, UInt32[masked_crc32c(header)])
38-
crc_data = reinterpret(UInt8, UInt32[masked_crc32c(data.data)])
37+
crc_data = reinterpret(UInt8, UInt32[masked_crc32c(event_bytes)])
3938

4039
write(out, header)
4140
write(out, crc_header)
42-
write(out, data.data)
41+
write(out, event_bytes)
4342
write(out, crc_data)
4443
flush(out)
4544
end

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ end
99
function serialize_proto(data)
1010
pb = PipeBuffer()
1111
encode(ProtoEncoder(pb), data)
12-
pb.data
12+
return view(pb.data, 1:pb.size) # Do not return additional zeros
1313
end
1414

1515
"""

0 commit comments

Comments
 (0)