wampcc
wampcc copied to clipboard
MsgPack integers error
Hello
I found an error in the message pack code (MSVC). Here is my example code:
json_array jin({ 50, 563234340645992 });
// encode
auto region = wampcc::json_msgpack_encode(jin);
std::vector<char> retval(region->second);
memcpy(retval.data(), region->first, region->second);
// decode
json_value jout = wampcc::json_msgpack_decode(retval.data(), retval.size());
cout << jin << endl;
cout << jout << endl;
Output: [50, 563234340645992] [50, 919383144]
Error is in json/src/msgpack_serialiser.cc:
case wampcc::eINTEGER: {
if (jv.is_int()) {
#ifdef WAMPCC_TRACE_MSGPACK
std::cout << "pack_long_long" << std::endl;
#endif
m_packer.pack_int(jv.as_int()); // TODO: raises warning on MSVC++
} else {
#ifdef WAMPCC_TRACE_MSGPACK
std::cout << "pack_unsigned_long_long" << std::endl;
#endif
m_packer.pack_unsigned_long_long(jv.as_uint());
}
break;
jv.is_int() is true for all integer types so int64 is packed as 32 bit value.
I'm not sure how to correct this error because track message: std::cout << "pack_long_long" << std::endl suggests that 32 bit ints should be packed as 64bit values ....
Hi,
Thanks for details error info. The error was indeed on the line you identified. I've fixed the code, and checked into the master branch.