-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
force msgpack_pack treat empty array as a map #45
Comments
I have a similar issue. While implementing a client for 3d party binary protocol which utilizes msgpack, I run into a problem that I need to send php indexed array as MP map, but msgpack_pack([0 => 'foo', 1 => 'bar'], MessagePack::MAP);
// or
msgpack_pack_map([0 => 'foo', 1 => 'bar']); |
Hello, will this feature be supported in future? thanks! |
Hi @zhangbiao2009 ! Let me check the other msgpack implementations, this may be out of scope. I get this is really useful, but you can just walk the returned structure and transform as needed. I just don't want to add needless complexity. thanks for taking time to file this! |
For the record, in PDOStatement::bindValue() one can pass an optional 3d parameter with explicit data type, e.g.:
So, for msgpack_pack([1, 2]); // will pack it to MP_ARRAY
msgpack_pack([1, 2], Msgpack::TYPE_MAP);
msgpack_pack([1, 2], Msgpack::TYPE_ARR);
msgpack_pack('42'); // will pack it to MP_STR
msgpack_pack('42', Msgpack::TYPE_INT);
msgpack_pack('2.4'); // will pack it to MP_STR
msgpack_pack('2.4', Msgpack::TYPE_FLOAT); |
Hello,
when use msgpack_pack() to pack an empty array, it is always treated as an array, but sometimes we want it to be treated as an empty map, just like what JSON_FORCE_OBJECT does for json_encode(). Does msgpack_pack() has options like this?
Thanks you.
The text was updated successfully, but these errors were encountered: