GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — force msgpack_pack treat empty array as a map · Issue #45 · msgpack/msgpack-php

force msgpack_pack treat empty array as a map #45

New issue
Copy link
New issue
Copy link
Open
Open
force msgpack_pack treat empty array as a map#45
Copy link
Labels
enhancement

Description

@zhangbiao2009
zhangbiao2009
opened on Apr 2, 2015
Issue body actions

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.

Activity

  1. rybakit commented on Apr 10, 2015

    @rybakit
    rybakit
    on Apr 10, 2015
    Contributor
    More actions

    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']);
  2. zhangbiao2009 commented on Jul 27, 2015

    @zhangbiao2009
    zhangbiao2009
    on Jul 27, 2015
    Author
    More actions

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

  3. Sean-Der
    added
    enhancement
    on Jul 28, 2015
  4. Sean-Der commented on Jul 28, 2015

    @Sean-Der
    Sean-Der
    on Jul 28, 2015
    Member
    More actions

    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!

  5. rybakit commented on Feb 24, 2016

    @rybakit
    rybakit
    on Feb 24, 2016
    Contributor
    More actions

    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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.