typed_lex_check
stdlib/typed/typed_lex_check.nbv
typed_lex_check(bytes, static types, static lens)
Constrain bytes to be a typed byte string in anondb's lexicographic encoding with the static schema types and lens (see typed_lex_width): fixed width fields concatenated with no separators. The schema fixes the total length, every byte is constrained to 0..255 and bool fields to 0 or 1.
Returns the bits of bytes, least significant bit of each byte first.
- Calls
bits/bytes_to_bits,typed/typed_lex_width- Precompiles
assert_eq!,constrain_mul!,if_eq!,len!,loop!- Used by
typed/typed_lex_chacha
Source
# Constrain `bytes` to be a typed byte string in anondb's lexicographic
# encoding with the static schema `types` and `lens` (see typed_lex_width):
# fixed width fields concatenated with no separators. The schema fixes the
# total length, every byte is constrained to 0..255 and bool fields to 0 or 1.
#
# Returns the bits of `bytes`, least significant bit of each byte first.
(bytes, static types, static lens)
static fields = len! types
assert_eq! fields, len! lens
static mut total = 0
loop! fields, i {
total = total + typed_lex_width(types[i], lens[i])
}
assert_eq! total, len! bytes
static mut offset = 0
loop! fields, i {
if_eq! types[i], 0 {
constrain_mul! bytes[offset], bytes[offset], bytes[offset]
}
offset = offset + typed_lex_width(types[i], lens[i])
}
bytes_to_bits(bytes)