Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: read compressed integers properly. #9

Merged
merged 1 commit into from
Apr 6, 2022

Conversation

abeaumont
Copy link
Contributor

Compressed integers were being read as unsigned VLQ which is not
correct. The encoding isn't exactly LEB128 either, it's very close to
unsigned LEB128, but the end result may be signed.

The way it works is as follows:

  • For 64-bit integers, unsigned LEB128 encoding is used, with a
    difference: the encoded number is limited to 9 bytes, and then in 9th
    byte all the 8 bits are encoded as is (so the 64 bit include 8
    bytes * 7 bits + 1 byte * 8 bits). For negative integers, the MSB
    will be set to 1.
  • For 16 and 32-bit integers, the same encoding is used, except
    only the less significant 16 and 32 bits respectively are
    non-zero. The resulting numbers are also signed and can be negative.

Part of #4

Compressed integers were being read as unsigned VLQ which is not
correct. The encoding isn't exactly LEB128 either, it's very close to
unsigned LEB128, but the end result may be signed.

The way it works is as follows:
- For 64 bit integers, unsigned LEB128 encoding is used, with a
difference: the encoded number is limited to 9 bytes, and the in 9th
byte all the 8 bits are encoded as is (so the 64 bit include 8
bytes  * 7 bits + 1 byte * 8 bits). For negative integers, the MSB
will be set to 1.
- For 16 and 32 bit integers, the same encoding is used, except the
only the less significant 16 and 32 bits respectively are
non-zero. The resulting numbers are also signed and can be negative.
@abeaumont abeaumont self-assigned this Apr 6, 2022
@abeaumont abeaumont merged commit 6bfb268 into main Apr 6, 2022
@abeaumont abeaumont deleted the fix/compressed-integer-reader branch April 6, 2022 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant