Skip to content
New issue

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

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

Already on GitHub? # to your account

Support maximal-length encoded integers #6

Open
alexcrichton opened this issue Jan 28, 2019 · 0 comments
Open

Support maximal-length encoded integers #6

alexcrichton opened this issue Jan 28, 2019 · 0 comments

Comments

@alexcrichton
Copy link

This came up during rustwasm/walrus#30, specifically rustwasm/walrus#30 (comment).

The use case here is that sometimes when dealing with leb128 you'll often have a scenario where a leb128 integer denotes how many bytes left in the region are part of a section or unit. When encoding, though, we often don't know the length of the section up-front, so a common trick is to do something like:

  • For a u32 encoded as leb128, reserve 5 bytes of space
  • Encode the entire section
  • Encode the length of the section into the previously reserved 5 bytes of space

This encoding uses the maximal instead of minimal width, using "padding zero bytes" that look like 0x80 to ensure that leb128 eats up all 5 of the bytes reserved.

It'd be neat if this crate supported such a use case (it's sort of like Seek with writers), although I'd be fine just supporting it with slices for the time being!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant