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

标签 c++ c linux ubuntu msgpack

我想打包一个大于 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 之前

最佳答案

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

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

关于c++ - MsgPack c++ 打包长度超过 32 个字符的字符串[Ubuntu],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25586999/

相关文章:

c++ - FFMPEG:多路复用不同持续时间的流

c++ - 时间:2019-05-10标签:c++ : invalid conversion from `const char* const' to `char*'

c - C中的条件语句和控制语句有什么区别吗?

c++ - 同一字符串的多个#define是否使用相同的常量字符串?

linux - Linux 中的 Oracle 数据库安装程序 [INS-10102] 安装程序初始化失败

java - 如何用最少的时间在mysql中转换大约1600万行?

c++ - 编译函数时遇到问题

c++ - 如何解析 "invalid operands of types ' const char [ ]' and ' const char *' to binary ' operator +' "

检查值是否在未定义的枚举中?

c - 柔性/Bison : yytext skips over a value