zserio
zserio copied to clipboard
Offsets should not be allowed in expressions
Consider the following schema:
struct WrongSchema
{
uint32 myOffset;
uint8 optionalValue if myOffset == 4;
myOffset:
string stringValue;
};
Such schema is not possible to fill by data correctly. Consider how the myOffset
will be calculated and what will happen during write and read operation.
- Let's say that
myOffset
will be initialized to0
. - Let's say that
optionalValue
will be set to0
. - Then
myOffset
will be set to4
(4
bytes because ofuint32
type +0
because of optionaluint8
which is not there0 != 4
). - Writer will write
myOffset == 4
,optionalValue = 0
,strigValue = "something"
. - Reader will fail because
myOffset == 4
but it should5
because optional is suddenly there.
We should reconsider usage of offsets:
One easy solution could be just to disable offsets in any Zserio expression.
Another solution could be that expressions with offsets can be used only after offset label. This is quite complicated and it is a question if this is usefull at all. For example, the following schema is ok:
struct CorrectSchema
{
uint32 myOffset;
myOffset:
string stringValue;
uint8 optionalValue if myOffset == 4;
};