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 — Add OPT_ASSOC for roundtrip serialization of map. by ranvis · Pull Request #58 · msgpack/msgpack-php

Conversation

@ranvis

@ranvis ranvis commented Aug 28, 2015

Copy link
Copy Markdown
Contributor

Since PHP has no real array, unpacking both array and map into array() can cause loss of information.
The patch adds OPT_ASSOC = false option to support roundtrip serialization of map by packing stdClass into map and vice versa like json_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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

taka-oyama, tyabu12, t-matsuno-777, and zeriyoshi reacted with thumbs up emoji
All reactions
  • 👍 4 reactions
@doc987

doc987 commented Aug 4, 2018

Copy link
Copy Markdown

It looks like this was never updated. Is there another way to deserialze to an object instead of an associative array?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@m6w6

m6w6 commented Dec 18, 2019

Copy link
Copy Markdown
Collaborator

Hi! Thanks for your submission.

Please rebase this PR, so we can have a closer look!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@m6w6 m6w6 added the enhancement label Dec 18, 2019
@ranvis
Add OPT_ASSOC for roundtrip serialization of map.
6b1845a
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.
@ranvis
ranvis force-pushed the assoc branch from 13c076b to 6b1845a Compare December 18, 2019 21:54
@ranvis

ranvis commented Dec 18, 2019

Copy link
Copy Markdown
Contributor Author

Done.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov-io

codecov-io commented Dec 18, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #58 into master will increase coverage by 0.17%.
The diff coverage is 92.3%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
msgpack_pack.c 94.42% <100%> (+0.04%) ⬆️
msgpack_unpack.c 82.76% <100%> (+0.35%) ⬆️
msgpack.c 93.33% <100%> (+0.12%) ⬆️
msgpack_class.c 87.55% <88.88%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7eb85f2...6b1845a. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ranvis

ranvis commented Dec 18, 2019

Copy link
Copy Markdown
Contributor Author

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"
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@taka-oyama

taka-oyama commented Apr 14, 2023

Copy link
Copy Markdown

@m6w6 Is this still considered?
I would love to have this feature implemented so the outcome is aligned with json!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@m6w6 m6w6 added this to the 2.1 milestone Jun 2, 2023
@m6w6
m6w6 merged commit 6b1845a into msgpack:master Aug 20, 2024
@codecov-commenter

codecov-commenter commented Aug 20, 2024

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.

Project coverage is 85.97%. Comparing base (7eb85f2) to head (6b1845a).
Report is 131 commits behind head on master.

Files Patch % Lines
msgpack_class.c 88.88% 2 Missing ⚠️

❗ 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.
📢 Have feedback on the report? Share it here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

m6w6 added a commit that referenced this pull request Aug 23, 2024
@m6w6
prepare 3.0.0RC1
b3ed0d7
* Add support for PHP-8.1 Enums
  * merges #173
  * fixes #171
* Add support for APCu
  * merges #162, #93
* Add OPT_ASSOC for roundtrip serialization of map.
  * merges #58
m6w6 added a commit that referenced this pull request Sep 25, 2024
@m6w6
prepare v3.0.0
a934abe
* Add support for PHP-8.1 Enums
  * merges #173
  * fixes #171
* Add support for APCu
  * merges #162, #93
* Add OPT_ASSOC for roundtrip serialization of map.
  * merges #58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

enhancement

Projects

None yet

Milestone

2.3

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@ranvis @doc987 @m6w6 @codecov-io @taka-oyama @codecov-commenter
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.