1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Big-endian key encoding helpers.
//!
//! Every sorted structure in this crate compares keys **byte-wise**
//! (`[u8]::cmp`). For that comparison to match the numeric order of the
//! encoded values, integers must be stored **big-endian**: the most
//! significant byte comes first, so lexicographic byte order equals numeric
//! order. (Little-endian encodings are only usable for equality lookups —
//! this is a classic pitfall.)
//!
//! Composite keys are built by concatenation: encode the most significant
//! component first. For example a temporal index key `(timestamp, id)` is
//! `write_u64(&mut buf[..8], ts)` followed by `write_u32(&mut buf[8..], id)`
//! — byte order then sorts by timestamp first, id second.
/// Encodes `v` big-endian into the first 4 bytes of `out`.
///
/// # Panics
///
/// Panics if `out.len() < 4`.
/// Decodes a big-endian `u32` from the first 4 bytes of `bytes`.
///
/// # Panics
///
/// Panics if `bytes.len() < 4`.
/// Encodes `v` big-endian into the first 8 bytes of `out`.
///
/// # Panics
///
/// Panics if `out.len() < 8`.
/// Decodes a big-endian `u64` from the first 8 bytes of `bytes`.
///
/// # Panics
///
/// Panics if `bytes.len() < 8`.
/// Encodes the composite key `(hi, lo)` big-endian into the first 12 bytes
/// of `out` (`hi` first — it is the more significant component).
///
/// This is the layout of e.g. the temporal index key
/// `[recorded_at: u64 | fact_id: u32]`.
///
/// # Panics
///
/// Panics if `out.len() < 12`.
/// Decodes a composite key previously encoded with [`write_pair`].
///
/// # Panics
///
/// Panics if `bytes.len() < 12`.