0

I want to pack my class from C++ Client to PHP Server and back. but when I try to pack a PHP class and unpack it to C++ Class I got a error.

this is my code in 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);

and after I send the packed binary data to C++ Client and try to unpack to the class

    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>();

and then I got an error named "msgpack::v1::type_error"

anyone knows what is the right way to pack and unpack a class between C++ and PHP?

dfeuer
  • 48,079
  • 5
  • 63
  • 167
Elyse
  • 111
  • 10

1 Answers1

0

question Solved: it is not support doing this anyway.

Elyse
  • 111
  • 10