184 lines
12 KiB
Markdown
184 lines
12 KiB
Markdown
# Data values, parsing and schema evolution
|
||
|
||
Status: planning only; feature tasks are **PLANNED**. Source baseline:
|
||
`f1f9ba375b22abf1adcc7c550ec21ac20895c0a4`, inspected 2026-11-24.
|
||
|
||
## Existing source and protected profile
|
||
|
||
[Data](../../../src/Data/module.cmake) declares Time; its reflection/CSV headers also
|
||
include Core. [Json](../../../include/Void/Data/Json.hpp) implements `Void::Json::Value`
|
||
with null/bool/double/string and boxed vectors for arrays/ordered object pairs. Integer
|
||
constructors convert to double; `as_int()` casts from it. General parsing returns
|
||
`std::expected<Value, ParseError>` with line/column diagnostics, retains duplicate object
|
||
pairs, provides JSON pointer access, SAX callbacks and serialization. SAX numeric
|
||
callbacks currently receive double. Exact 64-bit integers require a representation
|
||
change, not just a new accessor.
|
||
|
||
[Reflect](../../../include/Void/Data/Reflect.hpp) serializes C++26-reflected values,
|
||
annotations, containers, variants and chrono values, and has `MigrationChain` plus
|
||
versioned envelopes. [Csv](../../../include/Void/Data/Csv.hpp) exposes allocating Row/
|
||
Table parsing and reflection conversion; current parse returns a Table without malformed-
|
||
quote diagnostics. [Ini](../../../include/Void/Data/Ini.hpp) handles sections, values,
|
||
mutation and serialization. Neither is a full configuration policy engine.
|
||
|
||
[StrictJson](../../../include/Void/Data/StrictJson.hpp) is a separate namespace/type:
|
||
`Void::Json::Strict::Value` uses signed int64, ordered maps and restricted parsing.
|
||
[StrictJson tests](../../../tests/standalone/Data/StrictJson.cpp) require exact signed
|
||
64-bit endpoints and reject duplicates, floats, excessive nesting and lone surrogates.
|
||
**C-07 prohibits broadening this profile through general Data improvements.** Existing
|
||
[Update envelope parsing](../../../src/Update/Feed.cpp) uses general Json, not StrictJson;
|
||
schema 3 parses payload bytes for readable-document comparison before verifying their
|
||
signature. [Update](Update.md) explicitly plans moving that comparison after verification
|
||
and preserving a versioned legacy parsing profile. Verification before payload parsing is
|
||
the target contract; no general serializer becomes a replacement signing input. Existing
|
||
signed documents remain compatibility fixtures.
|
||
|
||
[General JSON](../../../tests/standalone/Data/Json.cpp),
|
||
[query/SAX](../../../tests/standalone/Data/JsonQuery.cpp),
|
||
[accessors](../../../tests/standalone/Data/JsonAccessors.cpp),
|
||
[reflection](../../../tests/standalone/Data/Reflect.cpp),
|
||
[annotations](../../../tests/standalone/Data/ReflectAnnotations.cpp),
|
||
[chrono](../../../tests/standalone/Data/ReflectChrono.cpp),
|
||
[CSV](../../../tests/standalone/Data/Csv.cpp),
|
||
[CSV reflection](../../../tests/standalone/Data/CsvReflect.cpp), and
|
||
[INI](../../../tests/standalone/Data/Ini.cpp) are current test sources. Partial graph
|
||
ranges Json 243/1090 and Reflect 595 were read directly. The graph's reflection call
|
||
edges include heuristic matches; source, not those edges, establishes type behavior.
|
||
|
||
## Target ownership and backend rationale
|
||
|
||
Keep the native DOM/scanners/reflection implementation. Data owns structured values,
|
||
general parsing policies, schema envelopes and migration; [Binary](Binary.md) owns
|
||
encoding primitives. [Math](Math.md) owns checked numeric conversions; Data may depend
|
||
downward on its small Numeric header. [Unicode](../subsystems/Unicode.md) is an explicit
|
||
validation/normalization adapter, never a hidden signed-data transform. Functional owns
|
||
common classifications and adapters for Data's path-aware domain errors. No optional
|
||
third-party JSON engine becomes a foundation requirement. Dependencies are declared and
|
||
independently tested, including Core and Time, under [C-01/C-07](../ARCHITECTURE.md).
|
||
|
||
## NEW value representation and checked conversion
|
||
|
||
Illustrative NEW members on `Void::Json::Value`, not current compiling API:
|
||
|
||
```cpp
|
||
namespace Void::Json {
|
||
enum class NumberKind { signed_integer, unsigned_integer, real };
|
||
// Value backing alternatives add int64_t and uint64_t alongside double.
|
||
// NumberKind Value::number_kind() const;
|
||
template<class T> std::expected<T, ConversionError> number_as(const Value&);
|
||
enum class DuplicateKeys { reject, first_wins, last_wins, preserve };
|
||
struct ParseOptions {
|
||
DuplicateKeys duplicate_keys = DuplicateKeys::reject;
|
||
std::size_t max_input_bytes = 16 * 1024 * 1024;
|
||
std::size_t max_owned_bytes = 64 * 1024 * 1024;
|
||
std::size_t max_string_bytes = 1024 * 1024;
|
||
std::size_t max_nodes = 1000000;
|
||
unsigned max_depth = 64;
|
||
};
|
||
std::expected<Value, ParseError> parse(std::string_view, ParseOptions);
|
||
}
|
||
```
|
||
|
||
Signed integer tokens in range become int64; nonnegative integers above INT64_MAX but
|
||
within UINT64_MAX become uint64. Integers outside both ranges fail rather than round
|
||
through double. Decimal/exponent tokens become finite double, with conversion range
|
||
errors reported. Arbitrary-precision decimals are outside the first value milestone;
|
||
a later named decimal capability requires a separate representation/schema decision.
|
||
Numeric lexemes are limited to 256 bytes. General parsing validates full grammar,
|
||
UTF-8 and escaped scalar pairs, and rejects trailing junk. Integer `-0` becomes integer
|
||
zero; floating negative zero retains sign and serializes as `-0.0`. Lexical preservation
|
||
is a separate borrowed raw-document facility, not a promise of the DOM.
|
||
|
||
`number_as<T>` delegates exact/range logic to Numeric and adds the document path.
|
||
Default integer-to-double conversion rejects inexactness; named lossy conversion is
|
||
explicit. Equality compares integral alternatives exactly with signedness checks;
|
||
integer/real equality is true only when the real is finite, integral and exactly matches
|
||
the integer. It never first converts UINT64_MAX to double. Typed wrong-kind access
|
||
reports an error; legacy throwing accessors remain adapters during the major migration.
|
||
|
||
Objects retain insertion order in vector pairs. Duplicate detection uses a temporary
|
||
key index charged to the owned-byte/node budget. Default reject avoids ambiguous lookup;
|
||
preserve exposes a multi-member API and requires an explicit occurrence policy for
|
||
lookup/pointer traversal. first/last-wins are deterministic named compatibility profiles.
|
||
Keys compare decoded bytes; normalization/case folding is never implicit. Programmatic
|
||
construction and serialization enforce the same duplicate/finite-number rules selected
|
||
for output. Stable pretty output is not a security canonicalization standard.
|
||
|
||
## Streaming, tables and ownership
|
||
|
||
Unify DOM and SAX grammar scanning with typed numeric events (`int64`, `uint64`, `double`).
|
||
NEW incremental parser owns incomplete tokens, uses at most the configured 1 MiB token
|
||
buffer, and reports consumed/need-more/completed/error states. Callback string views
|
||
expire at callback return; an explicit owned-event mode copies within budget. Callbacks
|
||
may stop parsing with an error/stop result. Check a supplied stop token between tokens
|
||
and every 4 KiB inside long strings; no Async dependency or worker is introduced.
|
||
Earlier SAX events remain observed after failure; a DOM result publishes only on full
|
||
success. Input plus owned output, key indexes, parser stack and migration scratch all
|
||
count toward explicit resource accounting; allocator overhead is reported separately.
|
||
|
||
CSV gets an incremental quoted-field state machine with exact malformed-quote offsets,
|
||
CRLF/LF policy, delimiter selection and defaults of 65,536 rows, 1,024 columns and 1 MiB
|
||
per field within 16 MiB input/64 MiB owned bytes. Empty final rows and embedded line breaks
|
||
have explicit fixtures. Row conversion reports column/name/type errors, not a blanket
|
||
nullopt. INI gets deterministic serialization, duplicate section/key policies (reject
|
||
by default in NEW strict mode), escaped-value rules, and the same byte bounds with
|
||
65,536 keys. Configuration owns overlays, environment expansion and secret policy.
|
||
|
||
Reflection decoding selects strict unknown-field rejection or an explicit ignore mode,
|
||
honors required/default/rename annotations and uses exact numeric conversions. Depth and
|
||
owned-byte budgets cover reflected containers too. MigrationChain validates a contiguous
|
||
version path before applying it; run each step on owned candidate data, cap at 32 steps,
|
||
and publish only after final validation. Migration failure never partially mutates the
|
||
caller's original value. No claim of database transactionality follows from this local
|
||
strong exception guarantee.
|
||
|
||
## NEW native binary value codec
|
||
|
||
Select **VoidValueBinary V1** in NEW `include/Void/Data/ValueBinary.hpp`, with no claimed
|
||
CBOR/MessagePack compatibility. Envelope: four literal bytes `VVB1`, one flags byte
|
||
(must be zero), then one value. Tags: 0 null, 1 false, 2 true, 3 ZigZag int64, 4 uvarint
|
||
uint64, 5 little-endian IEEE binary64, 6 length-prefixed UTF-8 string, 7 array count plus
|
||
values, 8 object pair count plus string keys/values. Varints are minimal. Reject nonfinite
|
||
floats, unknown tags/flags, duplicate keys in strict mode and trailing bytes. Preserve
|
||
array/object order; canonical signing is not part of V1. Defaults reuse Data budgets;
|
||
validate counts before reserve. Schema transport adds a Data-owned type ID and version
|
||
inside an explicit envelope value; RPC/Storage independently own their framing/durability.
|
||
|
||
## Ordered backlog
|
||
|
||
| Task | Phase; dependencies | Scope and acceptance | Recommended role |
|
||
| --- | --- | --- | --- |
|
||
| M-DATA-01 | P0; current source | Freeze general/StrictJson behavior and signed fixture boundaries; map Data includes and every numeric consumer before a representation break. | astra_implementer |
|
||
| M-DATA-02 | P1; M-MATH-02; M-DATA-01 | Add exact signed/unsigned representation and checked access/equality; endpoints and 2^53±1 survive parse/serialize/reflection without silent rounding. | astra_implementer |
|
||
| M-DATA-03 | P2; M-DATA-02; Functional/Memory bounded-error/resource gates | Implement explicit general JSON limits/duplicate policies and transactional DOM publication; adversarial inputs cannot bypass aggregate budgets. | sol_implementer |
|
||
| M-DATA-04 | P2; M-DATA-03 | Share scanner with typed SAX/incremental modes; all chunk splits match DOM grammar and callbacks never retain temporary views. | sol_implementer |
|
||
| M-DATA-05 | P2; M-DATA-02–03 | Complete reflection strictness, annotation diagnostics and bounded migration; failed version step preserves input and missing paths fail before execution. | sol_implementer |
|
||
| M-DATA-06 | P2; M-DATA-03 | Complete CSV/INI streaming/errors/deterministic output and typed rows; quote, duplicate, field-limit and rollback fixtures pass. | sol_implementer |
|
||
| M-DATA-07 | P3; M-BINARY-04; M-DATA-03/05 | Implement VVB1 with golden byte fixtures and versioned value envelope; unknown formats reject and resource limits match JSON. | sol_implementer |
|
||
| M-DATA-08 | P3; M-DATA-04–07; protected Update/Security fixture gate | Publish migration and installed consumers; signed documents retain their exact acceptance profile and no signature uses reserialized bytes. | astra_implementer |
|
||
|
||
## Validation, migration and rollback
|
||
|
||
CURRENT evidence is the inspected suites and parent baseline; no build/test/fuzz run was
|
||
performed for these documents. PROPOSED tests cover INT64_MIN/MAX, UINT64_MAX, oversized
|
||
integers, inexact casts, malformed exponents/UTF-8/surrogates, every duplicate mode,
|
||
deep/wide trees, escaped pointer keys, callback stop, chunk splits, allocation failure,
|
||
CSV quote state and interrupted migration. Keep a separate protected StrictJson fixture
|
||
set: general uint64/float/duplicate policies must not alter it. Cross-check VVB1 against
|
||
handwritten golden bytes, not only its own round trips.
|
||
|
||
Workload profiles include small config DOMs, 16 MiB tables, deep rejection, integer-heavy
|
||
messages and streaming scans. Measure p50/p95/p99, throughput, allocation count/bytes,
|
||
peak RSS/CPU and reflection build cost through [PERFORMANCE](../PERFORMANCE.md).
|
||
No throughput improvement or compiler support is claimed without that evidence.
|
||
|
||
[Migration](../MIGRATION.md) groups Value layout, number kind, default duplicate policy,
|
||
typed SAX events and reflection strictness into the major release. Preserve old general
|
||
parser behavior only in a named legacy adapter; StrictJson stays separate and unchanged.
|
||
Deploy VVB1 readers before enabling writers, retain old-format fixtures/readers and never
|
||
rewrite signed payloads in place. Rollback disables new-format writes; applications must
|
||
retain a readable prior-format copy before persisted migration. See
|
||
[VALIDATION](../VALIDATION.md), [DEPENDENCIES](../DEPENDENCIES.md),
|
||
[DELIVERY](../DELIVERY.md), [requirements](../REQUIREMENTS.md),
|
||
[Update](Update.md) and [Security](Security.md) for integration gates.
|