Skip to content

Commit

Permalink
vlq_base128_be: apply the same changes as in the *_le variant
Browse files Browse the repository at this point in the history
  • Loading branch information
generalmimon committed Oct 5, 2023
1 parent 51fc327 commit 0c3a821
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions common/vlq_base128_be.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ meta:
id: vlq_base128_be
title: Variable length quantity, unsigned integer, base128, big-endian
license: CC0-1.0
ks-version: 0.7
ks-version: 0.9
bit-endian: be
doc: |
A variable-length unsigned integer using base128 encoding. 1-byte groups
consist of 1-bit flag of continuation and 7-bit value chunk, and are ordered
Expand Down Expand Up @@ -30,26 +31,23 @@ types:
doc: |
One byte group, clearly divided into 7-bit "value" chunk and 1-bit "continuation" flag.
seq:
- id: b
type: u1
instances:
has_next:
value: (b & 0b1000_0000) != 0
- id: has_next
type: b1
doc: If true, then we have more bytes to read
value:
value: b & 0b0111_1111
- id: value
type: b7
doc: The 7-bit (base128) numeric value chunk of this group
instances:
last:
value: groups.size - 1
value:
value: >-
groups[last].value
value: |
(groups[last].value
+ (last >= 1 ? (groups[last - 1].value << 7) : 0)
+ (last >= 2 ? (groups[last - 2].value << 14) : 0)
+ (last >= 3 ? (groups[last - 3].value << 21) : 0)
+ (last >= 4 ? (groups[last - 4].value << 28) : 0)
+ (last >= 5 ? (groups[last - 5].value << 35) : 0)
+ (last >= 6 ? (groups[last - 6].value << 42) : 0)
+ (last >= 7 ? (groups[last - 7].value << 49) : 0)
+ (last >= 7 ? (groups[last - 7].value << 49) : 0)).as<u8>
doc: Resulting value as normal integer

0 comments on commit 0c3a821

Please sign in to comment.