Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with decoding a sequence of optionals with unique tags #21

Open
w00drow opened this issue Apr 8, 2024 · 0 comments
Open

Bug with decoding a sequence of optionals with unique tags #21

w00drow opened this issue Apr 8, 2024 · 0 comments

Comments

@w00drow
Copy link

w00drow commented Apr 8, 2024

Test:

#include "ut.hpp"
#include "ut_proto.hpp"

struct o_params : med::sequence<
        O<C<0x01>, FLD_UC>,
        O<C<0x02>, FLD_U8>,
        O<C<0x03>, FLD_U16>>
{
};

struct m_params : med::sequence<
        M<FLD_UC>,
        M<FLD_U8>,
        M<FLD_U16>>
{
};

struct params : med::sequence<
        M<FLD_U8>,
        O<C<0x04>, o_params>,
        O<C<0x05>, m_params>>
{

};


TEST(sequence, optional)
{
    params p1;

    p1.ref<FLD_U8>().set(0);

    p1.ref<o_params>().ref<FLD_U8>().set(1);

    p1.ref<m_params>().ref<FLD_UC>().set(2);
    p1.ref<m_params>().ref<FLD_U8>().set(3);
    p1.ref<m_params>().ref<FLD_U16>().set(4);

    uint8_t e_buffer[64];
    med::encoder_context e_ctx{e_buffer};
    encode(med::octet_encoder{e_ctx}, p1);

    uint8_t d_buffer[64];
    med::allocator d_alloc{d_buffer};
    med::decoder_context<med::allocator> d_ctx{e_ctx.buffer().get_start(), e_ctx.buffer().get_offset(), &d_alloc};
    params p2;
    med::decode(med::octet_decoder{d_ctx}, p2);

    EXPECT_NE(p2.get<m_params>(), nullptr);
}

Adding length to o_params fixes the problem (O<C<0x04>, L, o_params>) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant