PTWM
chain

ptwm_core::chain::wire

Wire encoding / decoding for Chain.

ptwm_core::chain::wire

Wire encoding / decoding for Chain.

rsmod

ptwm_core::chain::wire

crates/ptwm-core/src/chain/wire.rs:1
mod wire

Wire encoding / decoding for [`Chain`].

Every node's op-id is stored as a **u16 index** into the per-file Extension Table rather than the raw `OpId` discriminant. The writer interns each op into an [`ExtensionTableBuilder`] and writes the resulting index; the reader resolves each index back to an [`OpId`] via the file's [`ExtensionTable`]. # Blob format (Python-produced chain blobs) Chain blobs produced by the Python `Chain.to_bytes()` method use a **self-contained** format: ```text local_et_count: u32 local_et_entries: [ExtensionTableEntry; count] chain_bytes: (num_nodes, num_edges, num_terminals, lens, nodes, edges, terminals) ``` Use [`read_chain_blob`] to parse a self-contained blob (ET prefix + chain), and [`write_chain_blob`] to produce one. These are the public APIs for Python interop; the lower-level [`read_chain`] / [`write_chain`] functions operate on already-parsed tables.
rsfn

ptwm_core::chain::wire::read_chain

crates/ptwm-core/src/chain/wire.rs:147
pub fn read_chain(buf: &[u8], table: &ExtensionTable) -> Result<(Chain, usize), PtwmCoreError>

Decode a `Chain` from `buf` using `table` to resolve each node's u16 table index back to an [`OpId`]. Returns `(chain, bytes_consumed)`.

rsfn

ptwm_core::chain::wire::read_chain_blob

crates/ptwm-core/src/chain/wire.rs:353
pub fn read_chain_blob(blob: &[u8]) -> Result<(Chain, usize), PtwmCoreError>

Parse a **self-contained chain blob** (ET prefix + chain bytes), as produced by [`write_chain_blob`] or by the Python `Chain.to_bytes()` method.

Returns `(chain, bytes_consumed)`.
rsfn

ptwm_core::chain::wire::write_chain

crates/ptwm-core/src/chain/wire.rs:36
pub fn write_chain(chain: &Chain, builder: &mut ExtensionTableBuilder, out: &mut Vec<u8>) -> Result<(), PtwmCoreError>

Encode `chain` into `out`, interning each op's canonical id into `builder` and writing the resulting `u16` table index in place of the old `OpId` discriminant.

rsfn

ptwm_core::chain::wire::write_chain_blob

crates/ptwm-core/src/chain/wire.rs:333
pub fn write_chain_blob(chain: &Chain) -> Result<Vec<u8>, PtwmCoreError>

Serialize `chain` into a **self-contained blob** suitable for use as a Python chain blob or for any context where the caller does not have access to a shared file-level Extension Table.

The blob format is: ```text local_et_count: u32 local_et_entries: [ExtensionTableEntry; count] chain_bytes: (num_nodes, …, nodes_section, edges_section, terminals_section) ```