Finding the size of a protocol buffer message in Julia

Viewed 121

I've looked at the code in ProtoBuf.jl and didn't see anything obvious. Given an instance of a protocol buffer object in Julia, is there a way of finding out how many bytes it needs before actually calling writeproto()?

As a little background, I want to know this because following the protobuf message, I'm sending a good-sized data array. The protobuf documentation discourages incorporating large arrays as part of a message, so my intention is to publish: a) the size of the protobuf structure, b) the protobuf structure itself, and c) the data array. The receiver of the message can then do the necessary bookkeeping to read the protobuf contents and the data array.

In the meantime, I've come up with an ugly workaround:

write(iob, UInt32(0)) # set aside space for header size
headerSize = UInt32(writeproto(iob, rdmMessage.header))
sizeBytes = reinterpret(UInt8, [headerSize])
iob.data[1:4] = sizeBytes[:]
# Back to the respectable world
write(iob, rdmMessage.body[:])

Not pretty, but if anyone else is in the same boat that I am, it might be useful to them.

0 Answers
Related