MsgPack c++打包长度超过32个字符的字符串[Uubuntu]

MsgPack c++ packing a string longer than 32 characters[Ubuntu]

本文关键字:字符串 Uubuntu 字符 32个 c++ 包长度 MsgPack      更新时间:2023-10-16

我想打包一个大于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重新安装了它,现在它可以工作了。在我做这件事之前/配置

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

// 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 编译