Giter VIP home page Giter VIP logo

Comments (4)

alizain avatar alizain commented on August 16, 2024

The spec states that time must be a 48 bit integer only. The extra bits the string encoding format allows for is simply extra space that will never be used.

So whenever you take the 10 time characters, and convert them into bits, you will always get an integer that fits inside 48 bits (it'll be zero padded for the few thousand years anyways!).

Said another way, even if the entire 48 bits for time is used, the largest base32 string you could get is 7ZZZZZZZZZ. Only if you encode a number that is greater than that, you will have the data-loss you described above. However, the spec makes it clear that this situation will only occur in approximately 9000 years. It does not intentionally specify what to do when that time comes 😄

from javascript.

mmacedoeu avatar mmacedoeu commented on August 16, 2024

That's right when you encode time from the right to the left, so when decoding, the 2 bits data lost on the left will have no effect because only 48 bits is used anyway. It's just limiting the max time you can encode like already stated on spec. But just by reading the spec some could potentially encode 50 bits; the string representation of time requires 10x 5bits; from the left to the right meaning the 2 bits on the right would be lost. Most base32 encoding algos encode from the left to the right. But, for ulid, time encoding using this will lead to data truncation and unable to decode back to the original string representation. For the 80 bits random part there is no problem because there is exactly 16 x 5bits so you can encode/decode from the left or right without problems.

from javascript.

alizain avatar alizain commented on August 16, 2024

from javascript.

alizain avatar alizain commented on August 16, 2024

Updated the docs slightly, closing this issue. You're more than welcome to submit a PR for more clarification!

from javascript.

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.