【问题标题】:Msgpack between PHP and C++PHP 和 C++ 之间的 Msgpack
【发布时间】: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 之间打包和解包类的正确方法是什么?

【问题讨论】:

    标签: php c++ msgpack


    【解决方案1】:

    问题已解决:无论如何都不支持这样做。

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多