【发布时间】:2015-02-10 06:31:30
【问题描述】:
我想将我的课程从 C++ 客户端打包到 PHP 服务器并返回。但是当我尝试打包一个 PHP 类并将其解压缩到 C++ 类时,我得到了一个错误。
这是我的 PHP 代码
class maplemessage
{
var $nCode;
var $nType;
var $Text;
var $nRetrytime;
function setValue()
{
$this->nCode = 22;
$this->nType = 12;
$this->Text = "testmessage";
$this->nRetrytime = 81;
}
}
$msg1 = new maplemessage;
$msg1->setValue();
$binpacked = msgpack_pack($msg1);
在我将打包的二进制数据发送到 C++ 客户端并尝试解包到类之后
class maplemessage {
public:
int nCode;
int nType;
std::string Text;
int nRetrytime;
public:
MSGPACK_DEFINE(nCode, nType, Text, nRetrytime);
};
...
msgpack::unpacked unp;
msgpack::unpack(unp, tmpbyte.data(), tmpbyte.size());
msgpack::object obj = unp.get();
std::cout << obj << std::endl;
msg1 = obj.as<maplemessage>();
然后我收到一个名为“msgpack::v1::type_error”的错误
谁知道在 C++ 和 PHP 之间打包和解包类的正确方法是什么?
【问题讨论】: