20 Commits
Author SHA1 Message Date
glm-5.2 51806f4469 fix(typedef): Int64/Uint64, aligned-mode restrictions, read factory (ADR 099-102)
ADR-099 — Int64/Uint64 as first-class kinds:
- schema.rs: add Int64/Uint64 to TypeDefKind (19 kinds), type_size=8,
  natural_alignment=8, is_fixed_size=true, needs_endian=true, FromStr
- data_access.rs: add read_i64/write_i64/read_u64/write_u64 + tests
- sequential_reader.rs: add I64/U64 to FieldValue + dispatch arms + test
- engine.rs: add I64/U64 read_field/write_field dispatch arms
- validation.rs: add Int64/Uint64 validators (as_i64/as_u64 check) +
  registration + tests. Hand-written (not macro) to avoid clippy
  'comparison useless due to type limits' for the full-range check.

ADR-100 — reject non-final inline length-prefixed variable fields:
- offset_map.rs: compute_struct now checks if a variable-length field
  using inline length-prefixing (no maxLength, no offset-indirect) is
  non-final → TypedefError::Offset at compile time. Prevents silent
  data corruption (write_string clobbering subsequent fields).

ADR-101 — packed-mode read factory:
- engine.rs: Layout::Packed no longer stores a SequentialReader.
  sequential_reader() returns Option<SequentialReader> (owned, fresh)
  instead of Option<&SequentialReader>. The reader's cursor state is
  consumer-owned.

ADR-102 — reject TUnion in aligned mode:
- offset_map.rs: compute_field returns TypedefError::Offset for
  TypeDefKind::Union. Removed the dead compute_union_field,
  variant_size_range, and find_discriminator_field methods (had three
  bugs: no variant offsets, first-variant discriminator offset,
  misaligned variant region).

295 tests pass, clippy clean, workspace builds clean.
2026-07-22 09:37:05 +00:00
glm-5.2 14d9cf281f fix(typedef): remove unintended TypeDef:Uint64 from the engine
TypeDef:Uint64 was never specified in any ADR and was a partial, incomplete
addition: type_size() returned None (so is_fixed_size() was false),
OffsetMap::compute rejected it, LayoutBuilder::build would unreachable!()
panic on it, and the validator did not register a TypeDef:Uint64 keyword.
Only the SequentialReader path worked, and only because it dispatched
directly to data_access::read_u64 without consulting type_size().

Remove the variant from TypeDefKind, the read_u64/write_u64 primitives,
FieldValue::U64, the sequential-reader and engine dispatch arms, and the
associated tests. The engine now has exactly 17 first-class kinds, matching
the spec. All 286 tests pass; the workspace builds clean.
2026-07-21 13:40:03 +00:00
deepseek-v4-pro ce7ef1e31f refactor(typedef): introduce TypeDefKind enum for integer dispatch
Replace all string-based TypeDef:* kind matching with a 17-variant
TypeDefKind enum. The enum provides compile-time exhaustiveness
checking, integer discriminant dispatch (jump table), and type-safe
methods (type_size, natural_alignment, is_fixed_size, etc.).

- Add TypeDefKind enum with FromStr, Display, and helper methods
- Add get_typedef_kind_enum() and get_typedef_kind_loose_enum()
- Convert DiscriminatorKind::Byte.disc_type from String to TypeDefKind
- Convert FieldPosition.kind from String to TypeDefKind
- Convert all 8 dispatch sites from string matching to enum matching
- Remove legacy string-based type_size/natural_alignment/is_fixed_size
  wrapper functions — all call sites use enum methods directly
- Update tests to use enum variants
2026-07-21 12:07:39 +00:00
deepseek-v4-pro 72aa79b6ee refactor(typedef): deduplicate shared code, fix bugs, add macros
Bug fixes:
- sequential_reader: use get_typedef_kind_loose instead of strict
  get_typedef_kind so object-annotation form schemas parse correctly
- validation: string_factory/bytes_factory accept object-annotation form

Deduplication (moved to schema.rs):
- get_typedef_kind_loose (was in 3 files)
- is_fixed_size replaces local is_fixed_kind (was in 2 files)
- resolve_ref_or_inline + resolve_ref (was in 2 files)
- U32_SIZE and DISCRIMINATOR_PATH constants (were in 3-4 files)

New macros (src/macros.rs):
- define_int_validator!, define_uint_validator!,
  define_float_validator!, define_type_validator!
  (eliminate ~200 lines of boilerplate in validation.rs)
- define_read_write_endian!, define_read_write_ne!
  (eliminate ~320 lines of boilerplate in data_access.rs)

Net: ~1,170 lines removed, 288 tests pass, clippy clean
2026-07-21 11:32:22 +00:00
glm-5.2 0d39b7f12a style(typedef): apply cargo fmt across all source and test files
Resolve formatting differences flagged by cargo fmt --check during the
review checkpoint. No functional changes.
2026-07-21 10:42:57 +00:00
glm-5.2 bf868157d3 fix(typedef): resolve pre-existing clippy warnings in test code
- sequential_reader.rs: change test helper write_u32/write_string param from
  &mut Vec<u8> to &mut [u8] (clippy::ptr_arg)
- validation.rs: replace 3.14/2.71 with 3.5/2.5 in test instances to avoid
  clippy::approx_constant (f32::consts::PI approximation)
2026-07-21 10:40:43 +00:00
glm-5.2 937df02f85 test(typedef/tests): add comprehensive integration tests and POC round-trip tests 2026-07-21 10:39:27 +00:00
glm-5.2 db8f5d863d feat(typedef/engine): implement TypedefEngine integrating layout and validation 2026-07-21 10:29:05 +00:00
glm-5.2 1344157d59 feat(typedef): re-export Gen 4 layout engine types from lib.rs
Re-export ByteRange, OffsetMap, FieldPosition, LayoutBuilder, PackedLayout,
FieldValue, SequentialReader, and UnionDispatch at the crate root so consumers
can access the layout engine types without module-qualified paths. The
discriminator read functions (read_byte_discriminator, etc.) remain
module-qualified under alknet_typedef::tunion.
2026-07-21 10:23:22 +00:00
glm-5.2 11c10c0bb1 feat(typedef/layout-builder): implement packed sequential LayoutBuilder for protocol write-side 2026-07-21 10:22:24 +00:00
glm-5.2 835bed1c6f feat(typedef/sequential-reader): implement packed sequential SequentialReader for protocol read-side 2026-07-21 10:17:10 +00:00
glm-5.2 f754ae9cbe feat(typedef/offset-map): implement aligned static OffsetMap with natural alignment 2026-07-21 10:16:37 +00:00
glm-5.2 4b8e5c163a feat(typedef/tunion): implement TUnion discriminator dispatch for byte-offset and field-name 2026-07-21 10:14:50 +00:00
glm-5.2 1c6a705987 feat(typedef): re-export build_validator from validation module
Re-export validation::build_validator at the crate root so consumers can
call alknet_typedef::build_validator(schema) directly. The data_access
functions remain module-qualified (alknet_typedef::data_access::read_u32)
since there are 28 of them and re-exporting all would be noisy.
2026-07-21 10:03:28 +00:00
glm-5.2 03e1c5ee41 feat(typedef/data-access): implement primitive read/write for 17 TypeDef kinds with endianness 2026-07-21 10:02:13 +00:00
glm-5.2 f41387eeed feat(typedef/validation): implement custom keyword validators for all 17 TypeDef kinds 2026-07-21 10:01:53 +00:00
glm-5.2 28d4068e0e feat(typedef): re-export schema layer public API from lib.rs
Re-export Endian, VariableEncoding, DiscriminatorKind, and the parse_*
functions plus normalize_refs from the schema module so they're accessible
at the crate root alongside TypedefError.
2026-07-21 09:57:08 +00:00
glm-5.2 ac36a1cee3 feat(typedef/schema-types): implement TypeDef kind detection, annotations, Endian, $ref normalization 2026-07-21 09:56:40 +00:00
glm-5.2 109d743f9f feat(typedef/error-type): implement TypedefError enum with Schema, Offset, Access, Validation variants 2026-07-21 09:55:46 +00:00
glm-5.2 44f221e8cc feat(typedef/crate-init): initialize alknet-typedef crate skeleton
Created crates/alknet-typedef/ with Cargo.toml depending on jsonschema 0.46
(default-features = false for WASM-cleanliness) and serde_json with
preserve_order. Added src/lib.rs with module declarations for all 9 modules
and skeleton source files for each. Added crate to workspace members list.

Verified: cargo check, clippy -D warnings, and build --workspace all succeed.
Dependency tree confirmed free of tokio/reqwest/rustls (WASM-clean).
2026-07-21 09:54:05 +00:00