Skip to main content

decode

Function decode 

Source
pub fn decode<T: Document>(
    bytes: &[u8],
    expected_collection_id: u32,
) -> Result<T>
Expand description

Decode an on-disk record into a T: Document instance.

Validates the per-document header at the runtime boundary (power-of-ten Rule 5):

  1. bytes.len() >= DOC_HEADER_SIZE.
  2. header.collection_id == expected_collection_id.
  3. bytes.len() == DOC_HEADER_SIZE + header.payload_len.
  4. CRC32C of the payload matches header.payload_crc32c.
  5. header.type_version <= T::VERSION (no future versions).
  6. If header.type_version < T::VERSION, the codec consults T::historical_schemas() for the matching version, walks the payload through that schema via Dynamic::from_postcard_bytes, and dispatches into Migrate::migrate with the structured Dynamic (M10 #83). If no schema is registered for header.type_version, the codec returns Error::SchemaNotRegistered without invoking migrate — silent fallback hides schema-evolution bugs. Otherwise (versions match) the payload is decoded directly via postcard::from_bytes::<T>(payload).

§Errors