Bijou64: A variable-length integer encoding
inkandswitch.com
Bijou64: A variable-length integer encoding
1–10 of 93 posts
Re: Bijou64: A variable-length integer encoding
#2Re: Bijou64: A variable-length integer encoding
#3This seems quite convoluted just to avoid the "0 can be represented in more than one way" problem.
Re: Bijou64: A variable-length integer encoding
#4This seems quite convoluted just to avoid the "0 can be represented in more than one way" problem.
Re: Bijou64: A variable-length integer encoding
#5The 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 [1]: https://github.com/multiformats/multicodec
Re: Bijou64: A variable-length integer encoding
#6Re: Bijou64: A variable-length integer encoding
#7The upsides: the size of the integer is apparent upon reading the first byte, and every number has exactly one canonical representation. I wish C strings had been standardized around something similar, instead on null termination.
> ...adversarial input, which is rarely in the test suite.
This made my scratch my head. My tests for quite pedestrian APIs often contain adversarial input of obvious shapes. I though that for anything security-related (like the author's project) testing against adversarial input would be be a prominent part.
Re: Bijou64: A variable-length integer encoding
#8This seems quite convoluted just to avoid the "0 can be represented in more than one way" problem.
Re: Bijou64: A variable-length integer encoding
#9Maybe 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.
Re: Bijou64: A variable-length integer encoding
#10This looks neat, but if encoding/decoding performance is important, payload size isn't and the integer is bounded, I would just put a fixed-size integer into the payload as-is.
LEB128 (and JSON for that matter) can encode integer values of arbitrary length. This doesn't, which may or may not be important but it's different.
I'll admit that I do not do any cryptographic work with my library and therefore canonical representations aren't a huge concern in my use-cases. I merely provide various configurable limits (max value length, max depth, max items per collection) in an effort to prevent infinitely long documents from hogging my tokenizers indefinitely.