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):
bytes.len() >= DOC_HEADER_SIZE.header.collection_id == expected_collection_id.bytes.len() == DOC_HEADER_SIZE + header.payload_len.- CRC32C of the payload matches
header.payload_crc32c. header.type_version <= T::VERSION(no future versions).- If
header.type_version < T::VERSION, the codec consultsT::historical_schemas()for the matching version, walks the payload through that schema viaDynamic::from_postcard_bytes, and dispatches intoMigrate::migratewith the structuredDynamic(M10 #83). If no schema is registered forheader.type_version, the codec returnsError::SchemaNotRegisteredwithout invokingmigrate— silent fallback hides schema-evolution bugs. Otherwise (versions match) the payload is decoded directly viapostcard::from_bytes::<T>(payload).
§Errors
Error::Corruptionwithpage_id = 0on a malformed header or CRC mismatch (the codec does not know the page id; callers that need a specific id should wrap or re-emit).Error::CollectionIdMismatchon a collection-id mismatch.Error::SchemaVersionFromFutureon a stored record newer thanT::VERSION.Error::SchemaNotRegisteredwhen the storedtype_versionis older thanT::VERSIONandT::historical_schemas()has no entry for it.Error::SchemaMigrationNotImplementedwhen the registeredMigrate::migratebody returns the default error.Error::SchemaTypeMismatch/Error::SchemaDepthExceededon a schema / payload disagreement.Error::Codecon postcard decode failures.