Skip to content

Commit

Permalink
Refactor varint encoding (ordinals#2645)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagr authored Nov 9, 2023
1 parent 084a370 commit 48a6d6e
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/runes/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ pub fn encode_to_vec(mut n: u128, v: &mut Vec<u8>) {
let mut out = [0; 19];
let mut i = 18;

loop {
let mut byte = n.to_le_bytes()[0] & 0b0111_1111;

if i < 18 {
byte |= 0b1000_0000;
}

out[i] = byte;

if n < 0b1000_0000 {
break;
}
out[i] = n.to_le_bytes()[0] & 0b0111_1111;

while n > 0b0111_1111 {
n = n / 128 - 1;
i -= 1;
out[i] = n.to_le_bytes()[0] | 0b1000_0000;
}

v.extend_from_slice(&out[i..]);
Expand Down

0 comments on commit 48a6d6e

Please sign in to comment.