-
Notifications
You must be signed in to change notification settings - Fork 2
Add LEB128 functions for Nat and Int #1
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds LEB128 encoding and decoding functions for Nat and Int types, extending the existing functionality that only supported Nat64 and Int64. It also improves documentation by adding doc comments to all LEB128 functions and updates package metadata with additional keywords.
- Implements new LEB128 functions for
NatandInttypes (both encoding and decoding) - Adds comprehensive documentation comments to all LEB128 functions
- Updates package keywords to better reflect the library's functionality
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/lib.mo | Adds new LEB128 functions for Nat/Int types and doc comments for all LEB128 functions |
| tests/ByteUtils.Test.mo | Adds test coverage for the new Nat and Int LEB128 functions |
| tests/Sorted.Test.mo | Removes unused imports to clean up test file |
| mops.toml | Updates keywords array with more descriptive encoding-related terms |
|
Hey @f0i , thanks for the CR. Could you add a few more test cases for |
|
Benchmark workflows are failing for an unrelated reason - |
|
I added some test cases. #!/usr/bin/env python3
import leb128
def testULEB128(name, value):
print(name, value, [f'0x{byte:02x}' for byte in leb128.i.encode(value)])
def testSLEB128(name, value):
print(name, value, [f'0x{byte:02x}' for byte in leb128.i.encode(value)])
print("ULEB128")
testULEB128("2 ** 64", 2 ** 64)
testULEB128("2 ** 65", 2 ** 65)
testULEB128("2 ** 70", 2 ** 70)
testULEB128("2 ** 64 + 1", 2 ** 64 + 1)
testULEB128("123456789012345678901234567890", 123456789012345678901234567890)
print("")
print("SLEB128")
testULEB128("2 ** 64", 2 ** 64)
testULEB128("2 ** 65", 2 ** 65)
testULEB128("2 ** 70", 2 ** 70)
testULEB128("2 ** 64 + 1", 2 ** 64 + 1)
testULEB128("123456789012345678901234567890", 123456789012345678901234567890)
testULEB128("-1 * (2 ** 64)", -1*(2 ** 64))
testULEB128("-1 * (2 ** 65)", -1*(2 ** 65))
testULEB128("-1 * (2 ** 70)", -1*(2 ** 70))
testULEB128("-1 * (2 ** 64 + 1)", -1*(2 ** 64 + 1))
testULEB128("-123456789012345678901234567890", -123456789012345678901234567890)Output of that script: |
|
Thanks for adding these test cases. I'll merge and update the mops version |
|
@f0i v0.1.0 is published on mops: https://mops.one/byte-utils@0.1.0 |
NatandIntvalues.