PTWM
flavor

ptwm_core::flavor::router

PlaneCodecRouter: canonical-id-keyed dispatch for both built-in and third-party plane codecs.

ptwm_core::flavor::router

PlaneCodecRouter: canonical-id-keyed dispatch for both built-in and third-party plane codecs.

rsmod

ptwm_core::flavor::router

crates/ptwm-core/src/flavor/router.rs:1
mod router

`PlaneCodecRouter`: canonical-id-keyed dispatch for both built-in and third-party plane codecs.

# Dispatch order 1. **Built-ins** — resolved via [`dispatch_builtin`] and wrapped in [`BuiltinAdapter`]. 2. **Native** (`.so` / `.dylib` / `.dll`) — resolved by scanning `bundle_dir` for a native artifact, then dlopen-loaded via [`NativeExtension`]. 3. **WASM** — resolved by scanning `bundle_dir` for a `.wasm` artifact, then loaded via [`WasmExtension`]. 4. **Host** (Python) — not supported in this Rust-only router; returns [`CodecError::Unsupported`] with a clear message. The router caches resolved codecs by `CanonicalId` so repeated calls for the same id are free after the first lookup. # Wire-format note `PlaneRecord` now carries both `codec_id: CodecId` (closed enum, legacy) and `codec_table_idx: u16` (Extension Table index, C2 wire-format addition). When `codec_table_idx` is parsed, `decode_tensor` in `container.rs` resolves the `CanonicalId` via the Extension Table and validates availability through this router before dispatching the actual decode to the in-tree `PlaneCodec` implementation (for built-ins) or, for third-party codecs in a future task, to a dynamically-loaded extension.
rsfn

ptwm_core::flavor::router::decode_hex32

crates/ptwm-core/src/flavor/router.rs:445
pub fn decode_hex32(hex: &str) -> Option<[u8; 32]>

Decode a 64-character hex string into a 32-byte array. Returns `None` on any parse error (wrong length or non-hex character).

rstype

ptwm_core::flavor::router::DispatchedPlaneCodec

crates/ptwm-core/src/flavor/router.rs:55
pub trait DispatchedPlaneCodec

Uniform encode/decode surface exposed by the router.

The buffer ABI mirrors the flat ABI used by native and WASM extensions: input is a byte slice, output is caller-allocated. Returns the number of bytes written on success. `decode_with_state` is the state-aware variant used by the third-party branch of the container decode loop. Stateless codecs can ignore the state parameters; stateful codecs (per-group codebook, predictive scale coder, …) need them to round-trip planes whose state was captured in `PlaneRecord.{inline,shared}_state_bytes`.
rsfn

ptwm_core::flavor::router::find_native_path

crates/ptwm-core/src/flavor/router.rs:359
pub fn find_native_path(dir: &Path) -> Result<PathBuf, CodecError>

Scan `dir` for a native shared library (`.so` / `.dylib` / `.dll`) and return the first one found.

rsfn

ptwm_core::flavor::router::find_wasm_path

crates/ptwm-core/src/flavor/router.rs:377
pub fn find_wasm_path(dir: &Path) -> Result<PathBuf, CodecError>

Scan `dir` for a WASM module (`.wasm`) and return the first one found.

rsfn

ptwm_core::flavor::router::manifest_entry_for

crates/ptwm-core/src/flavor/router.rs:398
pub fn manifest_entry_for(install: &DiscoveredContribution, canonical_id: &CanonicalId) -> Result<ExtensionTableEntry, CodecError>

Synthesize a minimal `ExtensionTableEntry` from a `DiscoveredContribution` and a target `CanonicalId`.

The entry is used only to satisfy the `WasmExtension::load_from_path` / `NativeExtension::load` constructors; fields that are not required by those constructors are filled with safe defaults.
rstype

ptwm_core::flavor::router::PlaneCodecRouter

crates/ptwm-core/src/flavor/router.rs:213
pub struct PlaneCodecRouter

Resolves a `CanonicalId` to a `Box<dyn DispatchedPlaneCodec>`.

Construct once per decode session (or shared) and call [`get`] for each plane. Results are internally cached so expensive dynamic loads happen at most once per id.