What is the idea behind offsets? #646
Replies: 1 comment 2 replies
-
Thank you very much for such detailed description. Our documentation of offsets is very brief and I think that we should improve this. I don't think that you overlooked something.
Yes, you can omit storing the offset variable in the data. Actually, sometimes it is very difficult to calculate them. Therefore, the generated code offers
Yes, this is correct.
The main purpose and probably the only meaningful use case of the offsets is during the custom deserialization. Consider the following example:
Now, let's say we have whole So, in another words, we can do some optimization tricks during deserialization to skip deserialization of data which are not needed. |
Beta Was this translation helpful? Give feedback.
-
When I was reading the spec about offsets, I initially interpreted in that you can specify the position of a field in the bitstream.
For example, consider the following
zserio
struct:The way I interpreted it was that if I set
u32Offset
to 10,vi16OffsetArray
would be arranged at the start of the 10th byte of the binary blob:What actually happens in the serialization code generates an assertion that double-checks that the byte position in the reader matches
u32Offset
. If the byte position mismatchesu32Offset
, an assertion is thrown.In this scenario,
u32Offset
must/will be set to 4.It seems to me that offsets can be used to retrieve the position of a field within the byte stream after de-serialization, as some sort of assertion. This makes me wonder what is the purpose of the offset variable?
initialize_offsets()
?Thank you for your feedback, and please let me know if I overlooked or misunderstood something!
Beta Was this translation helpful? Give feedback.
All reactions