zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Offsets using parameters should not be allowed

Open mikir opened this issue 7 months ago • 3 comments

Consider the following schema:

struct OffsetHolder
{
    uint32 roomOffset;
};

struct Room(OffsetHolder offsetHolder)
{
offsetHolder.roomOffset:
    uint16 roomId;
};

struct School
{
    uint16 schoolId;
    OffsetHolder offsetHolder;
    Room(offsetHolder) room;
};

Such schema is completely valid but it prevents to pass parameters using const references (parameter offsetHolder in Room cannot be passed by const reference). This brings significant complexity for implementation of generators.

Because we cannot see any practical usage of this feature, it would be probable the easiest solution just to disable it. Perhaps, it will be enough to define offsets only where there are used:

struct Room
{
    OffsetHolder offsetHolder;
offsetHolder.roomOffset:
    uint16 roomId;
};

struct School
{
    uint16 schoolId;
    Room room;
};

mikir avatar Jul 02 '24 11:07 mikir