-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Milestone
Description
Currently offsets are implemented by mutable
keyword in the Data
abstraction. Such solution is simple, however it is not enough for offsets in unions or choices.
Consider the following example:
union TestUnion
{
uint32 offset;
string name[];
};
struct TestStruct
{
TestUnion unionField;
unionField.offset:
uint32 u32Field;
};
In this case, there is no field offset
in generated Data
, therefore keyword mutable
cannot be used. Because of that, the abstraction View
must accept non-const reference to the Data
:
template <>
class View<::offsets::offset_in_union::TestUnion>
{
public:
explicit View(::offsets::offset_in_union::TestUnion& data) noexcept;
::zserio::UInt32& offset() const;
ArrayView<const ::zserio::String> name() const;
::offsets::offset_in_union::TestUnion::Tag zserioChoiceTag() const;
const ::offsets::offset_in_union::TestUnion& zserioData() const;
protected:
View(::offsets::offset_in_union::TestUnion& data, const View& other) noexcept;
private:
::offsets::offset_in_union::TestUnion* m_data;
};
Therefore, it would be better to generate new dedicated abstraction OffsetInitializer
similarly to View. This new abstraction could accept non-const reference to the Data
and View
could accept const reference as expected.
Metadata
Metadata
Assignees
Labels
No labels