- AlkTypeEngine::compile gains a 4th param json_schema: Option<&Value>. When Some, a standard jsonschema::Validator is built from the consumer-provided JSON Schema and stored for the JSON-validation path. When None, validate_json returns AlkTypeError::Schema and is_valid_json returns false (D-BAST-007). - validate_json / is_valid_json signatures unchanged (per semver contract). Behavior: they now validate against the consumer JSON Schema, not a custom-keyword validator built from the alktype schema. The BAST document is not involved in this path. - build_validator repurposed (deferred decision #2): same signature, now builds a standard jsonschema::Validator with no custom keywords. Behavioral break, not a type break. Re-export kept. - Removed the 19 jsonschema::Keyword implementations and the 4 define_*_validator! macros (dead on the bytes path since step 5, now dead on the JSON path too). The is_rfc3339_timestamp helper lives on in bast_validation.rs (already copied there in step 5). - All compile call sites updated to pass None for json_schema (the layout/read/write/validate_bytes tests don't need JSON validation). - New tests: validate_json accepts/rejects against consumer JSON Schema, returns Schema error when no JSON Schema supplied, is_valid_json false when no schema, independence from BAST doc, malformed JSON Schema build error, nested object JSON Schema. Verification: - cargo test --release: 409 pass (332 lib + 77 integration) - cargo clippy --all-targets -- -D warnings: clean - cargo build --target wasm32-unknown-unknown --release: clean - cargo doc --no-deps: clean
73 lines
3.1 KiB
Rust
73 lines
3.1 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.
|
|
//! Borrows from the source `serde_json::Value` without cloning field
|
|
//! data.
|
|
//! - **Layout engine** ([`offset_map`], [`layout_builder`],
|
|
//! [`sequential_reader`]): Two layout modes — aligned static for
|
|
//! mmap-friendly formats, packed sequential for protocol wire formats.
|
|
//! All three consume the BAST typed tree.
|
|
//! - **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`]): two
|
|
//! validators for two paths. `bast_validation` is the BAST-native
|
|
//! validator for `validate_bytes` — a recursive walker over the BAST
|
|
//! type tree (D-BAST-006). `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 alktype
|
|
//! JSON Schemas at runtime, producing `serde_json::Value` (ADR-009).
|
|
//! (Step 7 converts the builder to emit BAST JSON.)
|
|
//! - **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 schema;
|
|
pub mod sequential_reader;
|
|
pub mod tunion;
|
|
pub mod validation;
|
|
|
|
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 schema::{
|
|
get_alktype_kind_loose, get_alktype_kind_loose_enum, inline_union_variant_refs, normalize_refs,
|
|
parse_align, parse_discriminator, parse_encoding, parse_endian, parse_max_length, resolve_ref,
|
|
resolve_ref_or_inline, DiscriminatorKind, Endian, AlkTypeKind, VariableEncoding,
|
|
};
|
|
pub use sequential_reader::{FieldValue, SequentialReader};
|
|
pub use tunion::UnionDispatch;
|
|
pub use validation::build_validator;
|