rocketsplash-formats 0.3.0

Shared data types and serialization formats for Rocketsplash TUI animations
Documentation
// <FILE>crates/rocketsplash-formats/src/col_peek_version.rs</FILE>
// <DESC>Peek the leading version byte of a MessagePack-encoded format struct</DESC>
// <VERS>VERSION: 1.0.0</VERS>
// <WCTX>Foundation crates 0.3.0 (RELEASE_PLAN D3 decode entry points)</WCTX>
// <CLOG>1.0.0: header-only version sniff so future-version files are rejected with UnsupportedVersion instead of a decode error.</CLOG>

/// Read the `version` field of a serialized `Splash`/`FontAtlas` without
/// decoding the payload.
///
/// Both formats serialize as a MessagePack array whose first element is the
/// `u8` version, so this only has to parse one array header and one integer.
/// Returns `None` when the bytes don't match that shape — callers then fall
/// through to the full decoder, which reports the real error.
pub(crate) fn peek_version(bytes: &[u8]) -> Option<u8> {
    let first = *bytes.first()?;
    let version_at = match first {
        0x90..=0x9f => 1, // fixarray
        0xdc => 3,        // array 16
        0xdd => 5,        // array 32
        _ => return None,
    };
    match *bytes.get(version_at)? {
        v @ 0x00..=0x7f => Some(v),                 // positive fixint
        0xcc => bytes.get(version_at + 1).copied(), // uint 8
        _ => None,
    }
}

// <FILE>crates/rocketsplash-formats/src/col_peek_version.rs</FILE>
// <VERS>END OF VERSION: 1.0.0</VERS>