wampcc icon indicating copy to clipboard operation
wampcc copied to clipboard

MsgPack integers error

Open Green7 opened this issue 7 years ago • 1 comments

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 ....

Green7 avatar Aug 01 '17 11:08 Green7

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.

darrenjs avatar Aug 02 '17 10:08 darrenjs