Every Bast* type drops <'a>: &'a str -> String, &'a Value -> Value (deferred decision 1: plain String/Value — the tree is built once; Arc<str> name-sharing needs a bench justification that doesn't exist). BastDoc::new(&Value, &str) still takes references in and clones into owned storage; the doc gains Clone. resolve_ref/resolve_typeref/ resolve_typeref_as_def return owned types. - Engine ownership flip: AlkTypeEngine holds the owned BastDoc (replacing bast_doc: Value + root_name: String; root_name() delegates to the doc), killing its three per-call BastDoc::new re-parses (aligned validate_bytes, read_field, write_field — the review #004 M1 pattern removed by construction; phase 5 retires the lookup_leaf_field walk itself). New public accessor root_name() (additive). Engine Send + Sync with the owned doc, asserted in the existing thread-share test. - Bonus cleanup: materialize_typeref_packed's dead _field param dropped (phase 2 left it dangling). Under ownership, keeping it would force a deep Value clone per array element / record value / union variant via dummy_field_for. The param, dummy_field_for, and ty_source are gone; no behavior change (the arg was already ignored). BastField::synthetic keeps an owned-signature #[allow(dead_code)] definition (no remaining callers today). - Consumers adapted: OffsetMap::compute(&BastDoc), materialize_aligned(&BastDoc, ...) (no lifetime), BuildCtx/ ComputeCtx hold &'d BastDoc, tunion/discriminator name borrows, lib.rs module doc. LayoutBuilder's doc_value re-parse cache is unchanged pending phase 4. Verification: 465 tests pass with zero test-logic changes (bast.rs suites exercise every parser path through the public API); clippy -D warnings clean; cargo doc zero warnings; wasm32 release build green.
82 lines
3.5 KiB
Rust
82 lines
3.5 KiB
Rust
//! alktype: The binary struct engine.
|
|
//!
|
|
//! Takes a BAST (Binary Abstract Syntax Tree) document and produces
|
|
//! an offset map, read/write functions, and validation — all driven
|
|
//! by the schema. The schema is the format definition; the engine is
|
|
//! generic.
|
|
//!
|
|
//! ## Architecture
|
|
//!
|
|
//! - **BAST parser** ([`bast`]): Typed tree over a BAST document —
|
|
//! `BastDoc`/`BastDef`/`BastStruct`/`BastField`/`BastType`/etc.
|
|
//! Owns its data (ADR-012 §2a) so consumers (`AlkTypeEngine`,
|
|
//! `LayoutBuilder`) can store the parsed tree without lifetime
|
|
//! entanglement; the clone happens once at `BastDoc::new`.
|
|
//! - **Layout engine** ([`offset_map`], [`layout_builder`],
|
|
//! [`sequential_reader`], [`read_plan`]): Two layout modes — aligned
|
|
//! static for mmap-friendly formats, packed sequential for protocol
|
|
//! wire formats. All consume the BAST typed tree; `read_plan` is the
|
|
//! packed read-side compiled form (ADR-011).
|
|
//! - **Data access** ([`data_access`]): Typed read/write at computed
|
|
//! offsets, zero-copy for fixed-size types.
|
|
//! - **TUnion dispatch** ([`tunion`]): Byte-offset and field-name
|
|
//! discriminator dispatch over `BastUnion`.
|
|
//! - **Validation** ([`validation`], [`bast_validation`],
|
|
//! [`validation_plan`]): two validators for two paths.
|
|
//! `validation_plan` is the compiled `ValidationPlan` — a
|
|
//! compile-once-walk-many constraint tree over the BAST document's
|
|
//! value-domain constraints, walked by `validate_bytes` per buffer
|
|
//! without re-touching the document (ADR-012 §3). `bast_validation`
|
|
//! hosts the one-shot `validate_value` wrapper over the plan.
|
|
//! `validation` builds a standard `jsonschema::Validator` from a
|
|
//! consumer-provided JSON Schema for `validate_json` /
|
|
//! `is_valid_json` (D-BAST-007) — no custom keywords, no BAST
|
|
//! involvement.
|
|
//! - **Builder** ([`builder`]): Fluent Rust API for constructing BAST
|
|
//! documents (binary layout) and standard JSON Schemas (JSON
|
|
//! validation) at runtime, producing `serde_json::Value` (ADR-009,
|
|
//! D-BAST-008). `struct_()` → BAST, `object()` → standard JSON Schema.
|
|
//! - **Materialize** ([`materialize`]): Materialize a `serde_json::Value`
|
|
//! tree from a binary buffer by walking the BAST typed tree. Used by
|
|
//! `AlkTypeEngine::validate_bytes` (ADR-010).
|
|
//! - **Engine** ([`engine`]): `AlkTypeEngine` — the compiled form of a
|
|
//! BAST document, combining layout and validation.
|
|
|
|
#[macro_use]
|
|
mod macros;
|
|
pub mod bast;
|
|
pub mod bast_meta;
|
|
pub mod bast_validation;
|
|
pub mod builder;
|
|
pub mod data_access;
|
|
pub mod engine;
|
|
pub mod error;
|
|
pub mod layout_builder;
|
|
pub mod materialize;
|
|
pub mod offset_map;
|
|
pub mod read_plan;
|
|
pub mod schema;
|
|
pub mod sequential_reader;
|
|
pub mod tunion;
|
|
pub mod validation;
|
|
pub mod validation_plan;
|
|
|
|
pub use bast_meta::BAST_META_SCHEMA;
|
|
pub use bast::{
|
|
BastArray, BastDef, BastDefKind, BastDiscriminator, BastDoc, BastEnum, BastField, BastRef,
|
|
BastRecord, BastStruct, BastType, BastUnion,
|
|
};
|
|
pub use builder::{Definitions, Discriminator, Schema};
|
|
pub use engine::{LayoutMode, AlkTypeEngine};
|
|
pub use error::AlkTypeError;
|
|
pub use layout_builder::{FieldPosition, LayoutBuilder, PackedLayout};
|
|
pub use offset_map::{ByteRange, OffsetMap};
|
|
pub use read_plan::{
|
|
CompositePlan, DiscriminatorPlan, FieldPlan, ReadKind, ReadPlan,
|
|
};
|
|
pub use schema::{Endian, AlkTypeKind, VariableEncoding};
|
|
pub use sequential_reader::{FieldValue, SequentialReader};
|
|
pub use tunion::UnionDispatch;
|
|
pub use validation::build_validator;
|
|
pub use validation_plan::{ValidField, ValidNode, ValidVariant, ValidationPlan};
|