ndsev / zserio

zero sugar, zero fat, zero serialization overhead
https://zserio.org/
BSD 3-Clause "New" or "Revised" License
108 stars 26 forks source link

[C++] Calling bitSizeOf() does not initialize objects #268

Open frank-aurich opened 3 years ago

frank-aurich commented 3 years ago

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

mikir commented 3 years ago

OK. We will put it to the backlog for now.