msgpack / msgpack-php

msgpack.org[PHP]
BSD 3-Clause "New" or "Revised" License
775 stars 120 forks source link

msgpack_unpack() failed to unpack data #44

Closed zhangbiao2009 closed 9 years ago

zhangbiao2009 commented 9 years ago

Hello, I use msgpack-c 1.0 to pack the following string: {"code":20004,"ex":"Unknow method","msg":"Socket: 5, address: 127.0.0.1:49120","raiser":"setasdf"}

my result is 82 bytes(hex): 84a4636f6465cd4e24a26578ad556e6b6e6f77206d6574686f64a36d7367d923536f636b65743a20352c20616464726573733a203132372e302e302e313a3439313230a6726169736572a773657461736466

Then I use msgpack-php to unpack it, but it failed: PHP Warning: msgpack Parse error ...

I guess it's because msgpack-c 1.0 pack data according to spec v5, but msgpack-php still not support spec v5. But I'm not sure this was the case. Or if it is true, is there any plan for msgpack-php to support spec v5?

Thank you.

Sean-Der commented 9 years ago

Hi @zhangbiao2009 ! Thanks for the bug report.

spec v5 was recently implemented, with master I get the following

Input

<?php

$input = hex2bin('84a4636f6465cd4e24a26578ad556e6b6e6f77206d6574686f64a36d7367d923536f636b65743a20352c20616464726573733a203132372e302e302e313a3439313230a6726169736572a773657461736466');
var_dump(msgpack_unserialize($input));

Output

array(4) {
  ["code"]=>
  int(20004)
  ["ex"]=>
  string(13) "Unknow method"
  ["msg"]=>
  string(35) "Socket: 5, address: 127.0.0.1:49120"
  ["raiser"]=>
  string(7) "setasdf"
}

Feel free to reopen this issue if you are still having problems, thanks!