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