2

i want to pack a string that is larger than 32 characters but the packer returns everytime 'da'.

When i use a string that contains less than 32 characters all works fine! But a larger string return only the 'da'

my code looks like follow:

msgpack::sbuffer sbuffer;
msgpack::packer<msgpack::sbuffer> packer(&sbuffer);

packer.pack(string("hello this is a string larger than 32 bytes"));

also tried this:

packer.pack_raw(43);
packer.pack_raw_body("hello this is a string larger than 32 bytes", 43);

In both cases return:

'da'

any idea?

thanks for help

edit: I fixed the problem... i reinstalled it with cmake and now it works. Before i did it with ./configure

nosvad
  • 21
  • 2
  • How are you getting the packed data? You might want to include that code as well. – Captain Obvlious Aug 30 '14 at 21:53
  • i create a string with a key that is 32 characters or higher and use the packer.pack() function to pack it and than i want to send it by a socket to another socket running on php. the problem the sbuffer only contains 'da' – nosvad Aug 30 '14 at 22:33

1 Answers1

1

I tried the following code and was able to retrieve the string:

// main.cpp
#include <iostream>
#include <string>
#include <vector>
#include <msgpack.hpp>

int main(int argc, char const *argv[])
{

  msgpack::sbuffer sbuf;
  msgpack::packer<msgpack::sbuffer> packer(&sbuf);

  packer.pack_raw(43);
  packer.pack_raw_body("hello this is a string larger than 32 bytes", 43);

  msgpack::unpacked msg;
  msgpack::unpack(&msg, sbuf.data(), sbuf.size());
  msgpack::object obj = msg.get();

  std::cout << obj << std::endl;

  return 0;
}

Compiled with g++ main.cpp -o main -lmsgpack

Chris Ledet
  • 11,458
  • 7
  • 39
  • 47
  • tried it with the same code that you written and still the same output... consol prints only 'da' – nosvad Aug 30 '14 at 22:50
  • Check and make sure that you are using the same compiler flags used to build the library. If they are different in any significant way it can cause the layout of objects to be different between your code and the library. This would have the affect of accessing the wrong data in the object. – Captain Obvlious Aug 30 '14 at 23:35
  • @nosvad How are you building the library? What version are you using? – Chris Ledet Aug 31 '14 at 00:34