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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! Native `.xmr` file format — the chunked container, the frozen `wire::vN`
//! types, the migration chain, and the CBOR codec. See
//! `src/core/FORMAT_RFC.md` for the specification and the reasoning.
//!
//! `no_std` + `alloc`, and independent of any importer: the format is the
//! project's own archival representation of [`crate::core::module::Module`],
//! distinct from the live model (which stays free to be refactored) and from
//! the derived serde repr the README used to recommend.
//!
//! This module is built in bottom-up layers, each testable on its own:
//!
//! - [`container`] — the byte grammar of §2: the 16-byte header and the
//! `[id][len][payload]` chunk stream, 8-byte aligned, with the PNG-style
//! critical / safe-to-copy case bits. Knows nothing of `Module`.
//! - [`wire`] — the frozen per-schema payload types ([`wire::v1`]) and the
//! CBOR codec. A shipped `vN` is never edited; a later schema redefines only
//! what changed (§6.4).
//! - [`pcm`] — the raw `PCM ` blob region (§4): sample bytes live outside CBOR,
//! 8-aligned and deduplicated by `Arc` identity.
//! - [`document`] — the assembler on top: [`document::write`] /
//! [`document::read`] turn a [`Module`](crate::core::module::Module) into
//! `.xmr` bytes and back, reporting what a read had to skip (§8).
//!
//! [`container`]: crate::format::container
//! [`wire`]: crate::format::wire
//! [`wire::v1`]: crate::format::wire::v1
//! [`pcm`]: crate::format::pcm
//! [`document`]: crate::format::document
//! [`document::write`]: crate::format::document::write
//! [`document::read`]: crate::format::document::read
/// Magic at byte 0 of every `.xmr` file: ASCII `"XMRS"`.
///
/// Four bytes where the extension has three, deliberately: a container magic
/// is a fixed-width field, an extension is a name. They do not have to match —
/// a `.png` starts with `\x89PNG`.
pub const MAGIC: = *b"XMRS";
/// Grammar version of the container itself (§2). Bumps ~never — only if the
/// byte layout of the header / chunk framing changes, which the in-band
/// `schema_version` is designed to make unnecessary.
pub const CONTAINER_VERSION: u16 = 1;
/// The highest `schema_version` this build implements — the reader's own
/// version (§6). A file whose `min_reader_version` exceeds this cannot be
/// interpreted correctly and is refused at the header.
pub const SCHEMA_VERSION: u32 = 1;
/// A 4-byte chunk id carrying the PNG-style case bits (§2.1). The two bits
/// are the entire forward-compatibility policy, with no table to maintain.
;
/// Everything that can go wrong reading a `.xmr` container. Structural only;
/// payload-decode (CBOR) errors join this enum with the wire layer.
///
/// `#[non_exhaustive]`: a format that will gain schema versions will gain
/// failure modes, and on a published API a new variant breaks every exhaustive
/// `match` downstream. Callers need a wildcard arm; that is the price of the
/// enum being able to grow at all.
/// Round a length up to the next multiple of the 8-byte chunk alignment.
pub const