I really like this idea. @jhawthorn suggested `^` instead of `o` though, and I really like it. ```ruby bytes = "\x01\x02\x03" offset = 0 leb128_value1, offset = bytes.unpack("R^", offset: offset) #=> 1 leb128_value2, offset = byt...tenderlovemaking (Aaron Patterson)
Applied in changeset commit:git|d0b72429a93e54f1f956b4aedfc25c57dc7001aa. ---------- Add support for signed and unsigned LEB128 to pack/unpack. This commit adds a new pack format command `R` and `r` for unsigned and signed LEB128 encod...tenderlovemaking (Aaron Patterson)
mame (Yusuke Endoh) wrote in #note-6: > That apparoach is unreliable because LEB128 is redundant. For example, both `"\x03"` and `"\x83\x00"` are valid LEB128 encodings of the value 3. Ah of course. I didn't think about that. 🤦♀️tenderlovemaking (Aaron Patterson)
This commit adds a new pack format command `R` and `r` for unsigned and signed LEB128 encoding. The "r" mnemonic is because this is a "vaRiable" length encoding scheme. LEB128 is used in various formats including DWARF, WebAssembly, MQ...tenderlovemaking (Aaron Patterson)
mame (Yusuke Endoh) wrote in #note-4: > It's a shame `unpack` doesn't tell you how many bytes it read. You'd probably want a `unpack` variant that returns the final offset too, or a specifier that returns the current offset (like `o`?)....tenderlovemaking (Aaron Patterson)
matz (Yukihiro Matsumoto) wrote in #note-2: > I am positive about the addition of LEB128. But I don't really like K/k because it doesn't remind me of LEB128 at all (though I know we've used L, E, B already). > ... Thanks for the feedba...tenderlovemaking (Aaron Patterson)
Sorry, I probably should have put an example in the original post. Here is a sample of the usage: ``` irb(main):003> [0xFFF].pack("K") => "\xFF\x1F" irb(main):004> [0xFFF].pack("K").unpack1("K") => 4095 irb(main):005> [-123].pac...tenderlovemaking (Aaron Patterson)
Hi, I'd like to add signed and unsigned LEB128 support to the pack and unpack methods. LEB128 is a variable length encoding scheme for integers. You can read the wikipedia entry about it here: https://en.wikipedia.org/wiki/LEB128 ...tenderlovemaking (Aaron Patterson)