substrate_data/wire/binary/tag.rs
1//! A value's first byte: what it is.
2
3/// The tags, each a constant, and [`ALL`] of them by name.
4macro_rules! tags {
5 ($($(#[$doc:meta])* $name:ident = $value:expr;)*) => {
6 $($(#[$doc])* pub const $name: u8 = $value;)*
7 /// Every tag, by its name (what other languages' readers are generated from).
8 pub const ALL: &[(&str, u8)] = &[$((stringify!($name), $value)),*];
9 };
10}
11
12tags! {
13 /// Null.
14 NULL = 0;
15 /// `false`.
16 FALSE = 1;
17 /// `true`.
18 TRUE = 2;
19 /// An integer, zigzag varint.
20 INT = 3;
21 /// A float, an `f64` little-endian.
22 FLOAT = 4;
23 /// A string: new (its bytes) or the table's.
24 STR = 5;
25 /// A list: a count, then the values.
26 LIST = 6;
27 /// A map: a count, then key and value pairs.
28 MAP = 7;
29 /// A reference: its kind and id strings.
30 REF = 8;
31 /// Bytes: a length, then them.
32 BYTES = 9;
33 /// A list of ints without a tag each: what a schema of numbers writes its lists as.
34 INTS = 10;
35 /// A list in a body of its own (its own strings): read lazily, cut out whole ([`crate::Stream`]).
36 STREAM = 11;
37 /// A float that is an `f32` exactly, 4 bytes.
38 FLOAT32 = 12;
39 /// Lists of floats without a tag each.
40 FLOATS = 13;
41 /// Lists of `f32`s without a tag each.
42 FLOATS32 = 14;
43 /// Version 2: a map whose keys are a shape (listed once, then named by
44 /// number): the shape, then one value per key.
45 MAP_SHAPE = 15;
46 /// Version 2: a list of maps that all have one shape: a count, the
47 /// shape, then each map's values with no tag of their own.
48 RECORDS = 16;
49}
50
51/// Version 2: the first of 128 tags that are an int by themselves,
52/// `tag - INT_INLINE + INLINE_INT_MIN` (-16 to 111): no payload.
53pub const INT_INLINE: u8 = 128;
54
55/// Version 2: the first of 32 tags that are a string already in the table,
56/// by its index `tag - STR_INDEX` (0 to 31): no payload.
57pub const STR_INDEX: u8 = 32;