Giter Site home page Giter Site logo

Comments (4)

rybakit avatar rybakit commented on June 20, 2024

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() serializes such arrays to MP array. So it would be nice to have a possibility to specify a type of the data to be serialized, e.g.:

msgpack_pack([0 => 'foo', 1 => 'bar'], MessagePack::MAP);
// or
msgpack_pack_map([0 => 'foo', 1 => 'bar']);

from msgpack-php.

zhangbiao2009 avatar zhangbiao2009 commented on June 20, 2024

Hello, will this feature be supported in future? thanks!

from msgpack-php.

Sean-Der avatar Sean-Der commented on June 20, 2024

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!

from msgpack-php.

rybakit avatar rybakit commented on June 20, 2024

For the record, in PDOStatement::bindValue() one can pass an optional 3d parameter with explicit data type, e.g.:

$stmt->bindValue(':foo', $foo, PDO::PARAM_INT);

So, for msgpack_pack() it may look like:

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

from msgpack-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.