2

我想打包一个大于 32 个字符的字符串,但打包器每次都返回“da”。

当我使用包含少于 32 个字符的字符串时,一切正常!但较大的字符串仅返回“da”

我的代码如下所示:

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

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

也试过这个:

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

在这两种情况下返回:

'da'

任何想法?

感谢帮助

编辑:我解决了这个问题......我用cmake重新安装了它,现在它可以工作了。在我使用 ./configure 之前

4

1 回答 1

1

我尝试了以下代码并能够检索字符串:

// 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;
}

编译g++ main.cpp -o main -lmsgpack

于 2014-08-30T22:03:17.937 回答