Git Product home page Git Product logo

Comments (5)

ugorji avatar ugorji commented on August 27, 2024

Taking a step back, it seems that you want support for sorted encoding of mappings. Is that a fair summary of your request?

from go.

warpfork avatar warpfork commented on August 27, 2024

Yep! That's the one thing I've hit in practice that was tricky for getting deterministic output.

I'd almost say that what I want is canonical cbor output, but with the interesting exception that I also need streams, which is technically a break from what the rfc suggests for canonical encoding.

I went ahead and made a prototype that does what I needed, so I'm going full steam ahead with using codec on that project (and it's fantastic! Thank you for all this awesome work!), but I did end up using GenHelperEncoder to do so despite the may-change-without-notice warnings. (We pin dependencies by commit hash in that project, so I'm not worried, and totally accept I might have to nontrivial refactors in the future. :) ) If you want to see the example of how that turned out, it's here and here.

It might also be nice to have a method for encoding maps that'll do keys in an order specified by a []string keys (well, or just expose an interface like the GenHelperEncoder officially where map appends can be called in the desired order directly) -- this would be useful in a situation where someone is implementating an encoding for something that has to match an existing spec that's deterministic order but not sorted.

from go.

ugorji avatar ugorji commented on August 27, 2024

K.

I have an upcoming change to support canonical encodings.

It works by configuring an option on the handle i.e. Canonical=true.

Canonical mode is ignored for code generation. It only works for the standard reflection-based runtime introspection. Also, there is a performance hit, as each key must be encoded out-of-band, then all key encodings compared, and then the key-values are encoded.

The good part is that it fits in with the rest of the library, so is supported.
Using "internal", "unsupported" APIs will prevent you from easy upgrade, so is highly discouraged.

The change should be uploaded today. Let me know if this will work for you before I make the update.

Thanks.

from go.

warpfork avatar warpfork commented on August 27, 2024

The performance hit caveat makes sense. Even with that, it'd definitely be great to have this in the supported APIs.

Do you think an explicit MapAppend(k, v interface{}) is also exposable? Maybe it's not the most general API, but I think it makes sense for most encoding formats I can think of, and it seems to make sense from the way the internals work right now (though I suppose what I wrote along those lines was cbor specific...). And raising some sort of "unsupported" error an encoding format doesn't support user-chosen map orders seems totally reasonable.

from go.

warpfork avatar warpfork commented on August 27, 2024

This is awesome! I look forward to using it in future protocols. :D

from go.

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.