0
我想將我的課程從C++ Client打包到PHP Server並返回。但是當我嘗試打包一個PHP類並將其解壓縮到C++類時,出現錯誤。PHP和C++之間的Msgpack
這是我在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之間打包和解壓縮類的正確方法是什麼?