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

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

Open
Avalanchecoder opened this issue May 24, 2023 · 3 comments
Open

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

Avalanchecoder opened this issue May 24, 2023 · 3 comments

Comments

@Avalanchecoder
Copy link

{"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)" ?

@redboltz
Copy link
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()));
}

@Avalanchecoder
Copy link
Author

Avalanchecoder commented May 25, 2023 via email

@redboltz
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants