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?