Add OPT_ASSOC for roundtrip serialization of map.#58
Conversation
|
It looks like this was never updated. Is there another way to deserialze to an object instead of an associative array? |
|
Hi! Thanks for your submission. Please rebase this PR, so we can have a closer look! |
Set OPT_ASSOC to false to pack stdClass instance in map and vice versa. Set OPT_PHPONLY to false in addition to pack any object into map.
|
Done. |
Codecov Report
@@ Coverage Diff @@
## master #58 +/- ##
==========================================
+ Coverage 85.79% 85.97% +0.17%
==========================================
Files 8 8
Lines 1345 1369 +24
==========================================
+ Hits 1154 1177 +23
- Misses 191 192 +1
Continue to review full report at Codecov.
|
|
usage: $msgpack = new MessagePack();
$msgpack->setOption(MessagePack::OPT_PHPONLY, false);
$msgpack->setOption(MessagePack::OPT_ASSOC, false);
$data = [0 => 1, 1 => 2, 2 => 3];
var_dump(bin2hex($msgpack->pack($data)));
// string(8) "93010203"
var_dump(bin2hex($msgpack->pack((object)$data)));
// string(20) "83a13001a13102a13203" |
|
@m6w6 Is this still considered? |
|
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #58 +/- ##
==========================================
+ Coverage 85.79% 85.97% +0.17%
==========================================
Files 8 8
Lines 1345 1369 +24
==========================================
+ Hits 1154 1177 +23
- Misses 191 192 +1 ☔ View full report in Codecov by Sentry. |
Since PHP has no real array, unpacking both array and map into
array()can cause loss of information.The patch adds
OPT_ASSOC = falseoption to support roundtrip serialization of map by packingstdClassinto map and vice versa likejson_encode/decode()does.This will improve compatibility a bit with data generated by other langauge bindings, while preserving the previous behavior when
OPT_ASSOC = true(default).Related to #18 #45