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
//! The stub-format machinery: a module per tag whose body is not yet mapped.
//!
//! A stub reads and writes the container — header parsed, checksum verified, body
//! kept verbatim — so every file round-trips byte-exactly while its body waits to
//! be reverse-engineered. The observed body length is recorded as data for tests,
//! never enforced on read: a raw body cannot misread, so an unexpected length is
//! preserved rather than refused.
/// Declare one stub format module: its tag, and the body length its corpus
/// specimens share (omit the length for variable-length library formats).
macro_rules! raw_format {
($(#[$meta:meta])* $name:ident, $tag:literal $(, $body_len:literal)?) => {
$(#[$meta])*
#[doc = ""]
#[doc = "Container-verified stub: reads and writes byte-exactly, header \
parsed and checksum verified, body kept verbatim and undecoded."]
pub mod $name {
use crate::cbin::{self, Cbin, RawBody};
use crate::error::Error;
use std::io::{Read, Seek};
pub const FORMAT: &str = $tag;
$(
/// The body length every corpus specimen holds. Observed, never
/// enforced on read: a raw body cannot misread, so a file of
/// another length is preserved rather than refused.
pub const BODY_LEN: u64 = $body_len;
)?
pub fn read_from(reader: &mut (impl Read + Seek)) -> Result<Cbin<RawBody>, Error> {
cbin::read(reader, FORMAT)
}
}
};
}
pub(crate) use raw_format;