Protobuf allows to measure the size of messages. This can be trivially implemented with:
data, err := picobuf.Marshal(msg)
return len(data)
However, it does have significant overheads due to needing the serialization.
There are two ideas how it can be implemented:
A. Generate a separate PicoSize(c *picobuf.Sizer, field picobuf.FieldNumber) or similar. This would allow to generate a significantly more efficient calculation for the size.
B. Modify picobuf.Encoder to allow encoding without appending bytes, but just counting. The specific implementations that don't use the relevant helpers can use: if c.IsSizing() { ... } to short circuit the logic. This might become somewhat complicated, because of the length header for messages.
Protobuf allows to measure the size of messages. This can be trivially implemented with:
However, it does have significant overheads due to needing the serialization.
There are two ideas how it can be implemented:
A. Generate a separate
PicoSize(c *picobuf.Sizer, field picobuf.FieldNumber)or similar. This would allow to generate a significantly more efficient calculation for the size.B. Modify
picobuf.Encoderto allow encoding without appending bytes, but just counting. The specific implementations that don't use the relevant helpers can use:if c.IsSizing() { ... }to short circuit the logic. This might become somewhat complicated, because of the length header for messages.