Closed hvbtup closed 4 years ago
Only RION Array and RION Table fields have a nested element count as first field. RION Object fields do not have this element count field.
The reasoning is, that for arrays and tables you will often have to allocate a Java array to hold the read values. The element count helps you allocate an array of the correct size before reading any of the elements.
An Object, on the other hand, is normally read into a Java object, or its fields are read one by one into local variables. Therefore a nested element count is not really "interesting" for Object fields.
Also, there was a time where the nested element count field of Array and Table was its own field type. This has later been changed to an IntPos field instead. Apparently the readElementCount() method has some issues still in this regard.
Remember to do a nextParse() right after moveInto() . In your code examples you are only doing a parse() ... and I cannot remember if that is enough right after a moveInto() call - but a nextParse() call will definitely work.
I think that the readElementCount() method should simply be removed. Now that element counts are simply IntPos fields, there is no reason to have an explicit method for reading element counts. That will just confuse people I think.
By the way, I have updated the RION Encoding tutorial to better explain how the encoding looks. The RION Encoding tutorial now contains encoding examples in hexadecimal notation for each field type.
I tried to write an object like this
And later on, to read it:
This failed when reading. It seems that the extended field with the type of 16 (meanging: element count) is not handled correctly when reading, this causes an off-by-one-error for the index.
As a workaround, I replaced writeElementCount and readElementCount with writeInt64 and readInt64, then it worked (see the commented lines in the code).
But this is probably not the way it's supposed to be.
It seems that the intention of using an extended type for specifying the element count has the following intention: The element count is optional. By using an extended type the element count can not be misinterpreted as something else, e.g. an integer value, if the keys are left out and the object contains just the values.