Skip to content

how to convert EXT(type:1,size=8) data in cpp #1072

Open

Description

@Avalanchecoder

{"signal_id":2801684810234,"type":"SIGNAL","signaltype":"NEW_ENTRY","exit_time":datetime.time(15,55),"remarks":26}
elif isinstance(obj, datetime.time):
# always encode in the 8-byte form
data = datetime.datetime.combine(
datetime.datetime.today(), obj)
data = int((obj.hour * 60 * 60 + obj.minute * 60 + obj.second) * 1e6
+ obj.microsecond)

    return KanhojiExtType(1, data.to_bytes(8, byteorder='big'))

this is my encoding logic
I am sending this from python. datetime format which in convert in "int" with type code 1

when i deserialise msgpack in cpp
{"signal_id":2801684810234,"type":"SIGNAL","signaltype":"NEW_ENTRY","exit_time":"EXT(type:1,size:8)","remarks":26}

could you help me to deserialising this field "exit_time":"EXT(type:1,size:8)" ?

Activity

  1. redboltz commented on May 25, 2023

    @redboltz
    Contributor

    When msgpack-c(C++) receives EXT format family MessagePack formatted byte stream, msgpack-c creates msgpack::object and its type is msgpack::type::EXT.
    See https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_object

    You can access msgpack::object directly as follows:

    BOOST_AUTO_TEST_CASE(simple_buffer_fixext1)

    Or you can use msgpack::type::ext or msgpack::type::ext_ref helper classes as follows:

    BOOST_AUTO_TEST_CASE(simple_buffer_ext_convert)
    {
    std::size_t const size = 65536;
    msgpack::sbuffer sbuf;
    msgpack::packer<msgpack::sbuffer> packer(sbuf);
    char buf[size];
    for (std::size_t i = 0; i != size; ++i) buf[i] = static_cast<char>(i);
    packer.pack_ext(sizeof(buf), 77);
    packer.pack_ext_body(buf, sizeof(buf));
    msgpack::object_handle oh =
    msgpack::unpack(sbuf.data(), sbuf.size());
    msgpack::type::ext e;
    oh.get().convert(e);
    BOOST_CHECK_EQUAL(size, e.size());
    BOOST_CHECK_EQUAL(77, e.type());
    BOOST_CHECK(
    std::equal(buf, buf + sizeof(buf), e.data()));
    }

  2. Avalanchecoder commented on May 25, 2023

    @Avalanchecoder
    Author
  3. redboltz commented on May 25, 2023

    @redboltz
    Contributor

    I recommend that create a simple code (no MAP, no AMQP).
    That is focused on msgpack EXT only like the test code I mentioned.
    And confirm the simple code works well, and then apply your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions