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 implement msgpack deserialized with Timestamp #1130

Open
NickLin910221 opened this issue Jun 24, 2024 · 2 comments
Open

How to implement msgpack deserialized with Timestamp #1130

NickLin910221 opened this issue Jun 24, 2024 · 2 comments

Comments

@NickLin910221
Copy link

With C++ 11 https://github.com/msgpack/msgpack-c.git branch:cpp_master

std::cout << message << std::endl;
msgpack::object_handle oh = msgpack::unpack(message.data(), message.size());

msgpack::object deserialized = oh.get();

std::cout << deserialized << std::endl;

Tick tick;
deserialized.convert(tick);

std::cout << "Received Tick: " 
          << "exchange=" << tick.exchange
          << ", code=" << tick.code
          << ", timestamp=" << tick.timestamp.seconds << "." << tick.timestamp.nanoseconds
          << ", close=" << tick.close
          << ", volume=" << tick.volume
          << std::endl;

I sent the msgpack packet with python in
{'exchange': 'TFE', 'code': 'TXFR1', 'timestamp': Timestamp(seconds=1718040379, nanoseconds=767436000), 'close': 21000.0, 'volume': 1.0, 'tick_Type': 0, 'simtrade': 1}

And I can receive msg payload in C++ as
{"method":"Publish","exchange":"TFE","code":"TXFR1","timestamp":"EXT(type:-1,size:8)","close":21000,"volume":1,"tick_Type":0,"simtrade":1}

And How to deserialized with the ext. type with Timestamp.

I use origin msgpack support msgpack.Timestamp to encode the packet

@redboltz
Copy link
Contributor

This test code could help you:

BOOST_AUTO_TEST_CASE(system_clock)
{
std::chrono::system_clock::time_point val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::object_handle oh =
msgpack::unpack(sbuf.data(), sbuf.size());
std::chrono::system_clock::time_point val2 = oh.get().as<std::chrono::system_clock::time_point>();
BOOST_CHECK(val1 == val2);
std::chrono::system_clock::time_point val3;
oh.get().convert(val3);
BOOST_CHECK(val1 == val3);
}

@NickLin910221
Copy link
Author

Thanks a lot.
It inspired me and helpful.

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