0

I am looking at the SSZ serialization for Ethereum and am unable to understand how the "index" alone can be used for encoding/decoding variable length fields. The following is quoted from ethereum.org site (emphasis added):

"For types with variable lengths, the actual data gets replaced by an "offset" value in that element's position in the serialized object. The actual data gets added to a heap at the end of the serialized object. The offset value is the index for the start of the actual data in the heap, acting as a pointer to the relevant bytes."

An example follows and I understand it except one part: The offset value is the index for the start of the actual data in the heap but where is the length information kept? I can only guess that the length is upto the next offset (if there is yet another variable length field in the schema). If so, for ease in decoding, is there some additional data structure (e.g. length for each index) that is serialized as part of the encoding?

1 Answer 1

1

The length is not kept, you just need to find the difference between the current offset and the offset of the next field. And you need to know the entire container size to calculate length of the last dynamic field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.