Closed jozefhopko closed 9 months ago
Consider this example
struct
{
bytes field1;
string field2 = "";
byte[] field3;
}
in the struct definition you'll have 3 offsets of unit32 pointing to the corresponding data later in buffer
[uint32(field1-offset)],[uint32(field2-offset)],[uint32(field3-offset)],[field1-size,field1-data],[field2-size,field2-data],[field3-size,field3-item1,...,field3-itemN]
Great, thanks for the fast response!
Using your example, I was wondering, why not just remove the
[uint32(field1-offset)],[uint32(field2-offset)],[uint32(field3-offset)]
and write directly
[field1-size,field1-data],[field2-size,field2-data],[field3-size,field3-item1,...,field3-itemN]
This would reduce the size and parsing complexity. Or am I missing a use-case where the offset has an advantage?
You need to know offsets to access struct fileds, otherwise you need to travel from filed1 to fieldN. Without offsets your data will be variadic size.
Perfect, makes sense, thanks for the clarification!
First of all, great project and implementation!
I was just wondering what is the motivation of using offset in binary for struct, string, vector etc. As described in the specification, these types are written by using [offset] which points to --> [size] [data..]
What is the advantage of using the offset for these data types? Why not just to write it directly after each other like bool or array attributes?
Thanks in advance!