PTWM
ptwm_core

ptwm_core::ptwc

Sections of the compact container (\x89PTWC): header, chain registry, index and footer. crate::container writes and reads whole files; crate::extension::compact_table and crate::tensor_record_compact hold the Extension Table and record codecs.

ptwm_core::ptwc

Sections of the compact container (\x89PTWC): header, chain registry, index and footer. crate::container writes and reads whole files; crate::extension::compact_table and crate::tensor_record_compact hold the Extension Table and record codecs.

rsmod

ptwm_core::ptwc

crates/ptwm-core/src/ptwc.rs:1
mod ptwc

Sections of the compact container (`\x89PTWC`): header, chain registry, index and footer. [`crate::container`] writes and reads whole files; [`crate::extension::compact_table`] and [`crate::tensor_record_compact`] hold the Extension Table and record codecs.

```text FILE = HEADER | EXTENSION TABLE | PRELUDE | REGISTRY | BODY | INDEX | FOOTER HEADER magic [u8; 9] \x89PTWC\r\n\x1a\n hflags u16 must be 0 (every bit is reserved) et_len varint compact Extension Table bytes prelude_len varint shared-state prelude bytes (legacy prelude layout) registry_len varint chain registry bytes meta_xxh64 u64 xxh64 (seed 0) of the header bytes before this field, then the Extension Table, prelude and registry bytes REGISTRY count varint at most 32768 (0x8000), so chain ids are 0..=0x7FFF (container::MAX_CHAIN_ID) chain × count varint chain_len, then a CW2 chain (chain::wire_compact) whose op_ref is an Extension Table index of a built-in transform; chain id = position BODY tensor records (tensor_record_compact), back to back INDEX count varint at most (index bytes) / 3 entry × count varint name_len (1..=65535), UTF-8 name, varint rec_len (>= 3), in body order FOOTER index_len u64 sentinel [u8; 8] \x89TWMEOF\x1a (the legacy EOF sentinel) ``` The body starts right after the registry and the index right after the body: the record lengths must add up to exactly the bytes between them, and names must be unique. Each section parser gets exactly its slice and must consume all of it. Integers are little-endian and varints are canonical unsigned LEB128 ([`crate::varint`]), so each file has one encoding for what it holds. The registry limit is the same as the legacy `ChainRegistry` limit: the largest chain id is 0x7FFF, so a registry holds at most 0x8000 chains. Synthesis section 2 writes "count ≤ 0x7FFF"; this layout reads that as the bound on chain ids, so a model that fits the legacy registry also fits the compact one. There is no version field. A future layout change sets an `hflags` bit, which current readers reject.
rsfn

ptwm_core::ptwc::header_bytes

crates/ptwm-core/src/ptwc.rs:75
pub fn header_bytes(et: &[u8], prelude: &[u8], registry: &[u8]) -> Vec<u8>

Serialize the header for sections of the given bytes.

rsfn

ptwm_core::ptwc::locate_sections

crates/ptwm-core/src/ptwc.rs:105
pub fn locate_sections(buf: &[u8]) -> Result<Sections, PtwmCoreError>

Locate and check the sections of a compact container: magic, `hflags`, section lengths, footer, and `meta_xxh64`. The caller checks the EOF sentinel first.

rsconst

ptwm_core::ptwc::MAX_NAME_LEN

crates/ptwm-core/src/ptwc.rs:68
pub const MAX_NAME_LEN

Longest tensor name.

rsfn

ptwm_core::ptwc::read_index

crates/ptwm-core/src/ptwc.rs:251
pub fn read_index(buf: &[u8], body: Range<usize>) -> Result<Vec<IndexEntry>, PtwmCoreError>

Parse the index of a body at `body` (absolute range). Returns entries sorted by `(name_hash, name)` with absolute offsets; their names are set.

rsfn

ptwm_core::ptwc::read_registry

crates/ptwm-core/src/ptwc.rs:193
pub fn read_registry(buf: &[u8], table: &ExtensionTable) -> Result<ChainRegistry, PtwmCoreError>

Parse a chain registry that fills `buf` exactly. Op references resolve through `table`, whose entry must be a built-in transform.

rstype

ptwm_core::ptwc::Sections

crates/ptwm-core/src/ptwc.rs:93
pub struct Sections

Byte ranges of each section of a compact container.

rsfn

ptwm_core::ptwc::write_index

crates/ptwm-core/src/ptwc.rs:229
pub fn write_index(entries: &[(String, u64)]) -> Result<Vec<u8>, PtwmCoreError>

Encode the index for `(name, record length)` pairs in body order.

rsfn

ptwm_core::ptwc::write_registry

crates/ptwm-core/src/ptwc.rs:163
pub fn write_registry(registry: &ChainRegistry, op_index: impl ?) -> Result<Vec<u8>, PtwmCoreError>

Encode the chain registry. Chain ids must equal their positions; a Source node with empty params is written as a bound Source. `op_index` maps an op to its Extension Table index.