Giter Site home page Giter Site logo

Comments (3)

ongteckwu avatar ongteckwu commented on May 15, 2024

My output for the test case for the typescript implementation https://github.com/ongteckwu/typeid-ts matches this repo's.

from typeid-go.

loreto avatar loreto commented on May 15, 2024

@alisa101rs Thanks for reporting.

I ran two tests:

  1. I tried the encoding using ulid (which uses the same alphabet), it matched
  2. I tried the encoding using gos standard base32 library, but with the custom alphabet ... it did not match.

So there's a discrepancy between the two approaches. I'm doing some more testing to determine what should be the "right" way to encode typeids and will clarify the spec. I'll circle back.

from typeid-go.

loreto avatar loreto commented on May 15, 2024

OK, I did a bunch of testing, and I think the original implementation in this repo is still correct.

In particular the current implementation aligns the encoding of the typeid in an intuitive way with UUIDs. So that,
the typeid prefix_00000000000000000000000001 corresponds to the UUID 00000000-0000-0000-0000-000000000001. I added a test to check for that here: https://github.com/jetpack-io/typeid-go/blob/main/typeid_test.go#L100

Note that the standard base32 algorithm works in groups of 5 bytes, and therefore is subject to add padding at the end
of the byte array one is trying to decode. In our case though, we use an algorithm without padding that works byte by byte; to make the standard base32 algorithm work, padding would have to be added to the front of the array.
I added a test to validate that here: https://github.com/jetpack-io/typeid-go/blob/main/base32/base32_test.go#L11

from typeid-go.

Related Issues (7)

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.