Bijou64: A variable-length integer encoding

(inkandswitch.com)

38 points | by justinweiss 52 minutes ago

3 comments

  • willtemperley 0 minutes ago
    Maybe someone can explain why an encoder would ever create the padding bytes allowed in LEB128. I contributed the parser for LEB128 in apple/swift-binary-parsing and I’m still none the wiser. I’m genuinely mystified.
  • stebalien 5 minutes ago
    I've used LEB128 (with canonicalisation) extensively and... this looks so much nicer for most use-cases (length prefixed, supports the full uint64 range without that extra 10th byte).

    The downside is the encoding size. LEB128 quickly grows to 2 bytes, but stays at 2 bytes all the way to 2^14. This is important if you're using these numbers as tags/identifiers as we were in the multicodec [1] project, or for network message lengths. bijou64 only gives you 500 <= 2 byte numbers.

    [1]: https://github.com/multiformats/multicodec

  • RedShift1 11 minutes ago
    This seems quite convoluted just to avoid the "0 can be represented in more than one way" problem.
    • nine_k 8 minutes ago
      It allows finding out the length (and allocating memory) after reading the first byte.
    • ahoka 6 minutes ago
      I think it's neat.