zserio
zserio copied to clipboard
[C++] Calling bitSizeOf() does not initialize objects
In C++, calling Object::write() will initialize any child objects if not already done explicitly, but calling Object::bitSizeOf() does not.
For objects that need to be initialized, the initialization values should be part of the constructor.
Currently, you can create such objects just fine, but when trying to write them using BitStreamWriter, an exception will be thrown.
Consider an object:
struct Position(uint shift)
{
int<(31-shift) + 1> x;
int<(31-shift) + 1> y;
}
This code works fine:
BitStreamWriter bsw;
Position pos(162791424, 609027496);
pos.write(bsw);
but this will throw an exception:
Position pos(162791424, 609027496);
const auto bitSize = pos.bitSizeOf();
Expected
bitSizeOf should behave the same way as write
OK. We will put it to the backlog for now.