Coder Social home page Coder Social logo

Comments (6)

freitagbr avatar freitagbr commented on August 21, 2024

Suggestion: reimplement as a struct (a Varint should be immutable). Allow instantiation from an Int, and Array, or Bytes. Add encoded and decoded methods that return the UInt64 and Bytes representations, respectively.

from crystal-uvarint.

nfischer avatar nfischer commented on August 21, 2024

If we're returning UInt64 from an instance, how about we override .to_i and its similar functions? .to_u64 would be the one which actually returns the UInt64.

This might be a good opportunity to use templates for metaprogramming. That keeps the code base simple to maintain, but very flexible and extensible.

Also, it makes sense to provide a .to_s(base : Int32). Then Multihash can use .to_s(16) for serializing. If we want to expose the Bytes, we can add a method for that specifically.

from crystal-uvarint.

freitagbr avatar freitagbr commented on August 21, 2024

This should be closed by #2. For multihash, we can use the method .hexstring for the desired behavior.

from crystal-uvarint.

nfischer avatar nfischer commented on August 21, 2024

@freitagbr this wasn't fixed in #2 (see the title & description). #2 addressed some of the extra features mentioned in comment 1 & 2. Actually, #4 is a duplicate of this.

from crystal-uvarint.

freitagbr avatar freitagbr commented on August 21, 2024

Oh, you're right. I will mark #4 as a duplicate. PR #5 should fix the remaining issues here.

from crystal-uvarint.

freitagbr avatar freitagbr commented on August 21, 2024

This should be closed by #5.

from crystal-uvarint.

Related Issues (4)

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.