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:1066
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::DeltaSchemeRouter

crates/ptwm-core/src/flavor/router.rs:380
pub struct DeltaSchemeRouter

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

Same shape as [`PlaneCodecRouter`], minus the built-in step: `ptwm` ships zero built-in `delta_scheme` contributions today, so resolution goes straight to the installed-extension search (native preferred over WASM). Results are cached by `CanonicalId`, same as `PlaneCodecRouter`.
rstype

ptwm_core::flavor::router::DispatchedDeltaScheme

crates/ptwm-core/src/flavor/router.rs:335
pub trait DispatchedDeltaScheme

Uniform encode/decode surface for a resolved `delta_scheme` contribution.

Mirrors [`DispatchedPlaneCodec`], but over the two-buffer delta ABI: `encode(base, target) -> delta`, `decode(base, delta) -> target`.
rstype

ptwm_core::flavor::router::DispatchedHardwareBackendCuda

crates/ptwm-core/src/flavor/router.rs:471
pub trait DispatchedHardwareBackendCuda

Uniform decode surface for GPU-accelerated decode operations.

Provides two methods: `dispatch_decode_cuda` for decoding on CUDA devices, and `cuda_stream_handle` to acquire a stream for a given device ordinal.
rstype

ptwm_core::flavor::router::DispatchedPlaneCodec

crates/ptwm-core/src/flavor/router.rs:57
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`.
rstype

ptwm_core::flavor::router::DispatchedPlaneCodecCuda

crates/ptwm-core/src/flavor/router.rs:717
pub trait DispatchedPlaneCodecCuda

A plane codec that operates on CUDA device pointers.

Distinct from [`DispatchedPlaneCodec`], whose buffers are host memory. Implementors move no data across the host boundary: both input and output stay device-resident.
rsfn

ptwm_core::flavor::router::find_native_path

crates/ptwm-core/src/flavor/router.rs:980
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:998
pub fn find_wasm_path(dir: &Path) -> Result<PathBuf, CodecError>

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

rstype

ptwm_core::flavor::router::HardwareBackendRouter

crates/ptwm-core/src/flavor/router.rs:529
pub struct HardwareBackendRouter

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

Same shape as [`DeltaSchemeRouter`], with two deliberate differences. First, there is no WASM branch: a `u64` device pointer cannot be expressed in WASM's 32-bit linear address space, so `hardware_backend` is native-only by construction. Second, [`resolve`](Self::resolve) runs [`check`] against the entry's declared capabilities before attempting a native load, using `self.policy`; see [`Self::new`] and [`Self::new_with_policy`] for how that policy is chosen.
rsfn

ptwm_core::flavor::router::manifest_entry_for

crates/ptwm-core/src/flavor/router.rs:1019
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::NativePlaneCodecCudaAdapter

crates/ptwm-core/src/flavor/router.rs:745
pub struct NativePlaneCodecCudaAdapter
rstype

ptwm_core::flavor::router::PlaneCodecCudaRouter

crates/ptwm-core/src/flavor/router.rs:825
pub struct PlaneCodecCudaRouter

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

Same shape as [`HardwareBackendRouter`]: a `Mutex<HashMap<..>>` cache, the same `new` / `new_with_policy` constructor split, and the same `hardware_class`-presence precondition gated through [`check`] against `self.policy` before any native load is attempted. See [`HardwareBackendRouter::resolve`]'s doc comment for the full reasoning behind that precondition; it applies here unchanged. It differs from [`HardwareBackendRouter`] in two ways. First, it caches `Arc<dyn DispatchedPlaneCodecCuda>` and constructs [`NativePlaneCodecCudaAdapter`] rather than `NativeHardwareBackendCudaAdapter`. Second, a `plane_codec` contribution that resolves to a real installed manifest entry but has no loadable native artifact reports a fixed, non-formatted message ("plane_codec CUDA dispatch requires the native flavor") rather than one naming the canonical id and bundle directory: a WASM contribution cannot hold device pointers (WASM's linear address space is 32-bit), so this router is native-only by construction, exactly like [`HardwareBackendRouter`].
rstype

ptwm_core::flavor::router::PlaneCodecRouter

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

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

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