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

MsgPack integers error #6

Closed
Green7 opened this issue Aug 1, 2017 · 1 comment
Closed

MsgPack integers error #6

Green7 opened this issue Aug 1, 2017 · 1 comment

Comments

@Green7
Copy link

Green7 commented Aug 1, 2017

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

darrenjs added a commit that referenced this issue Aug 2, 2017
@darrenjs
Copy link
Owner

darrenjs commented Aug 2, 2017

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.

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