Skip to content
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

Use Types::Serialiser::Boolean for true/false #17

Open
wisnij opened this issue Aug 6, 2014 · 5 comments
Open

Use Types::Serialiser::Boolean for true/false #17

wisnij opened this issue Aug 6, 2014 · 5 comments

Comments

@wisnij
Copy link

wisnij commented Aug 6, 2014

Could Types::Serialiser::Boolean be used rather than defining Data::MessagePack::Boolean internally? Using and checking for that during conversion would make interoperability with other serialization formats a lot easier. In particular, it would be a big win to be able to convert from JSON text to Perl data and then into MessagePack, and vice versa, without having to account for the boolean types manually.

@gfx
Copy link
Member

gfx commented Aug 8, 2014

Looks nice. Patches welcome!

@FGasper
Copy link

FGasper commented Mar 22, 2017

I’m working on a module to support WAMP, a messaging/RPC protocol. That protocol supports MessagePack, but it’s a bit clumsy to implement because D::MP only uses its own boolean objects.

Can you point me in the appropriate direction for accessing and testing equality of a Perl global from XS? I may try to find time to work on this.

FGasper added a commit to FGasper/msgpack-perl that referenced this issue Mar 28, 2017
Issue msgpack#17: Types::Serialiser is useful to support for interoperability
with other CPAN serialization modules like JSON. This patch provides
that capability in both XS and PP.
@foobargeez
Copy link

Ah, I am stuck with this one as well -- JSON->Perl data->MP -- fails.

Looks like a MR has already been submitted to address this -- #37.

Is there anything I can help with to have the fix merged into the module?

Thanks in advance!

@foobargeez
Copy link

Something in production broke because of this issue, so I had to come up with a workaround. Sharing it here so it helps others who may be looking for one:

  • If your input has blessed booleans, store them as \1 or \0. In my case, I am dealing with TOML files, so something like:
        my $parser = TOML::Parser->new(
            inflate_boolean => sub {
                my $boolean = shift;
                return $boolean eq 'true' ? \1 : \0;
            }
        );
  • Data::MessagePack stores the data as Data::MessagePack::Boolean blessed objects
  • Once you unpack the data, do an unbless (from Data::Structure::Util)

That should do the trick until the Data::MessagePack deals with Types::Serialiser::Boolean blessed objects.

@FGasper
Copy link

FGasper commented Sep 26, 2017

@foobargeez I’m not sure why my PR is closed, but it expands compatibility to Types::Serialiser while maintaining compatibility with the proprietary flags.

This module appears to be abandoned, though. I tried to contact the maintainer several times and got no response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants