Coder Social home page Coder Social logo

Comments (9)

Micka33 avatar Micka33 commented on May 26, 2024

Issue originally posted in msgpack/msgpack#188

from msgpack-ruby.

iconara avatar iconara commented on May 26, 2024

I disagree. I don't think it would be a good idea to make #to_msgpack use #as_json. That method is not at all standardized and would mean that MessagePack started acting differently when you load another gem that happens to add #to_json to things.

For example: Cql::TimeUuid doesn't have a #as_json method (I know, I'm the author of cql-rb, where that class comes from, I assume that it's Cequel that adds it). If you decided to use cql-rb directly and not through Cequel, or just copied the code to a project where you don't use Cequel your code would suddenly stop working.

from msgpack-ruby.

iconara avatar iconara commented on May 26, 2024

An alternative, that wouldn't have the same problem, would be to check for a #to_h method and fall back on that it if exists. There would still be no guarantee that the value returned from the method would be MessagePack'able.

At the same time, this is what the MessagePack extensions should be used for. The Ruby and JRuby implementations don't support them very well at the moment, unfortunately.

from msgpack-ruby.

Micka33 avatar Micka33 commented on May 26, 2024

I didn't realize as_json was a rails only method! to_h seems to be a good alternative then.

What about the bignum too big to convert error? (Should I open a new issue?)

irb(main):002:0> {"n"=>81669062298108866050539035482603516879}.to_msgpack
RangeError: bignum too big to convert into `unsigned long long'
    from (irb):2:in `to_msgpack'
    from (irb):2
    from /Users/mickael/.rvm/rubies/ruby-2.1.5/bin/irb:11:in `<main>'

from msgpack-ruby.

iconara avatar iconara commented on May 26, 2024

What about the bignum too big to convert error? (Should I open a new issue?)

It's easier to track issues if they are reported separately, so yes please. We can leave this issue open as a feature request for the #to_msgpack/#to_h thing.

from msgpack-ruby.

Micka33 avatar Micka33 commented on May 26, 2024

Created it in #57

from msgpack-ruby.

cosmo0920 avatar cosmo0920 commented on May 26, 2024

If you want msgpack to support big integer, comment is welcomed in msgpack repo's issue: msgpack/msgpack#206

from msgpack-ruby.

simonrussell avatar simonrussell commented on May 26, 2024

Isn't this what custom serialisation (extension types) is for?

from msgpack-ruby.

tagomoris avatar tagomoris commented on May 26, 2024

Right. Use ext types for this purpose. I missed to close this.

from msgpack-ruby.

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.