Skip to content

Implement offsets using new abstraction similarly to View #81

@mikir

Description

@mikir

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions