zserio icon indicating copy to clipboard operation
zserio copied to clipboard

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

Open frank-aurich opened this issue 5 years ago • 1 comments

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

frank-aurich avatar Dec 10 '20 09:12 frank-aurich

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

mikir avatar Dec 10 '20 12:12 mikir