typed_width
stdlib/typed/typed_width.nbv
typed_width(static t, static n)
Byte width of a field of a typed byte string with type tag t and parameter n, in postcard's encoding. Tags:
0 bool, 1 u8: one byte, `n` must be 0
2 u16, 3 u32, 4 u64, 5 u128: a varint of `n` bytes, at most 3, 5, 10 or
19
6 bytes (Vec<u8>, String): the varint of the length `n`, then `n` bytes
7 option marker: one byte equal to `n`, 0 for None and 1 for Some, which
is followed by the field of the inner value
8 byte array ([u8; N]): `n` bytes
- Calls
typed/typed_varint_len- Precompiles
assert_eq!,assert_lt!,assert_lte!,if_eq!,if_lt!- Used by
typed/typed_bytes_check
Source
# Byte width of a field of a typed byte string with type tag `t` and
# parameter `n`, in postcard's encoding. Tags:
# 0 bool, 1 u8: one byte, `n` must be 0
# 2 u16, 3 u32, 4 u64, 5 u128: a varint of `n` bytes, at most 3, 5, 10 or
# 19
# 6 bytes (Vec<u8>, String): the varint of the length `n`, then `n` bytes
# 7 option marker: one byte equal to `n`, 0 for None and 1 for Some, which
# is followed by the field of the inner value
# 8 byte array ([u8; N]): `n` bytes
(static t, static n)
static VARINT_MAX = [3 5 10 19]
assert_lt! t, 9
static mut w = n
if_lt! t, 2 {
assert_eq! n, 0
w = 1
}
if_lt! 1, t {
if_lt! t, 6 {
assert_lt! 0, n
assert_lte! n, VARINT_MAX[t - 2]
}
}
if_eq! t, 6 {
w = typed_varint_len(n) + n
}
if_eq! t, 7 {
assert_lt! n, 2
w = 1
}
w