Skip to content

0085 — The geometry graph has a versioned wire format ​

  • Status: Accepted
  • Date: 2026-10-10
  • Deciders: Friedrich Schrödter
  • Supersedes: —

Context ​

Issue #267. A source adapter lowers its geometry into axiolid-model's GeometryGraph, and its language bindings (JavaScript/WASM, Python, C, .NET) want to hand that neutral representation to a host as a value: a viewer or a kernel in another language could then evaluate the exact geometry itself instead of receiving only triangles. That makes the graph a wire format, and until now it was only a Rust data structure. No encoding was documented, and nothing said which changes to GeometryNode, Primitive, Profile or a curve or surface variant break a serialised graph, as opposed to breaking the Rust API.

The maintainer decisions on #267 bind this record: commit now; a JSON and a binary encoding behind an optional serde feature, off by default; the binary encoding is CBOR; every payload carries an explicit format version; additions are minor, renames, removals and changes of meaning or units are major; and a reader that meets content it does not know refuses the whole payload by name, never skips it.

ADR 0011 declined a flat serialised view until a real consumer existed. One exists now. ADR 0039 asks that any serialised protocol be explicitly versioned and preserve unknown fields or fail closed; this format fails closed.

Decision ​

We will publish one versioned wire format for GeometryGraph, named axiolid-geometry-graph, starting at version 1.0, with two encodings of the same serde data model: JSON (RFC 8259, via serde_json) and CBOR (RFC 8949, via ciborium). axiolid-model owns the format, its version and its reader; the representation crates whose values the graph carries derive Serialize/Deserialize behind their own optional serde features and own no policy.

Envelope ​

Every payload is one map with exactly three entries, in this order:

json
{
  "format": "axiolid-geometry-graph",
  "version": "1.0",
  "graph": { "nodes": [ ... ], "roots": [ 0, 3 ] }
}
  • format is the literal name. Any other value, or none, is refused.
  • version is the string "MAJOR.MINOR", two decimal integers.
  • graph.nodes lists the nodes in insertion order, which is topological; a node reference is the zero-based index of an earlier node. graph.roots lists root indices in the caller's order.

Data model ​

  • Enums are externally tagged. A unit variant is its name as a string ("Union"); any other variant is a one-entry map from its name to its content ({"Primitive": {"Sphere": {"radius": 1.0}}}). A newtype variant's content is the wrapped value, a struct variant's content is a map of its fields, and a tuple field is an array. Rust enum discriminants never reach the wire.
  • Names are the Rust names as of format 1.0: node kinds, variants and fields keep the spelling they had when this format was published. A later Rust rename must keep the wire name with #[serde(rename = "...")]; the committed golden payloads (crates/representations/modeling/graph/tests/wire/) fail the build if it does not.
  • Vectors and transforms are arrays in the layout glam's own serde support writes: a 2D or 3D point or vector is [x, y] or [x, y, z]; a 3D affine transform is twelve numbers, the three columns of its linear part then the translation; a 2D affine transform is six numbers in the same column order.
  • An absent optional value is written as null; a reader treats a missing optional field as absent as well.
  • Integers (node and topology indices, degrees, multiplicities) are unsigned integers. Real numbers are IEEE-754 doubles and round-trip bit-exactly: JSON writes the shortest decimal that reads back to the same double, -0.0 included, and CBOR writes the shortest IEEE float (half, single or double) that holds the value exactly.
  • An integer reads as a real when it is exactly a double. JavaScript and Python CBOR encoders routinely write whole-number doubles as integer items, and JSON has one number type, so where a real is expected both readers accept an integer i with i as f64 as i128 == i (every |i| <= 2^53, and larger integers that are doubles); a lossless conversion cannot produce wrong geometry. A CBOR integer that is not exactly a double is refused as Malformed, naming its path, wherever it stands: no index or count of the format reaches 2^53, and rounding one would change the geometry silently. Integer zero has no sign and reads as +0.0; a payload that needs -0.0 writes it as a float, as this writer does. The CBOR reader maps the decoded item tree onto the JSON data model before deserialising, so the two encodings are read by one deserialiser; it unwraps the self-describe tag (55799) and refuses every other tag, byte strings, simple values, non-text map keys and repeated keys as Malformed.
  • Numbers are finite. JSON cannot carry a NaN or an infinity, so neither encoding does: a writer refuses a graph holding one, naming where it is, and a reader refuses a payload holding one. Lengths and angles keep the units the Rust values document (the caller's length unit, radians).

Version rules ​

ChangeVersion
Add a node kind, an enum variant, or an optional field (absent means what the payload meant before)minor
Rename or remove a kind, variant or field; change a field's type, meaning or units; make an optional field requiredmajor
Change the envelopemajor

A payload of an older minor of the same major stays readable by every later reader of that major. The committed golden payloads are the regression guard: each published version keeps its own, and today's reader must read each one to the identical graph.

A writer labels each payload with the lowest version that represents it (#297, see the note below), so an older reader keeps reading every payload that does not use what a later minor added.

Refusal rules ​

A reader returns a typed WireError and no graph whenever it cannot guarantee the whole payload:

  • Version first. Before reading the graph, the reader checks the envelope. A wrong or missing format is UnknownFormat, a missing version is MissingVersion, and a version it cannot parse, of another major, or of a newer minor than it supports is UnsupportedVersion, naming the version found and the version supported. A newer minor is refused even though it might contain nothing new, because the reader cannot know that without the vocabulary it lacks.
  • Unknown kinds and variants. A node kind or variant the reader does not know, in a payload whose version it supports, is UnknownKind, naming the kind and the payload's version. It is never skipped: skipping would return incomplete geometry silently.
  • Unknown fields. A field the reader does not know is UnknownField. Adding a field is a minor change, so a genuine newer payload is already refused by its version; an unknown field in a supported version is a malformed or hand-edited payload.
  • Validation on read. A decoded graph is rebuilt node by node through GeometryGraphBuilder::push, the same validation as any other construction: references to earlier nodes of the right family, dimension rules, station rules. A failure is InvalidGraph, naming the node index and the GraphError. There is no unchecked construction path; a node reference deserialises only inside a graph payload, where it takes the new graph's brand.
  • Everything else that does not decode (bad syntax, a wrong type, a missing required field, trailing bytes, exceeding the decoders' nesting limit) is Malformed, with the decoder's message. A non-finite number (a CBOR NaN or infinity, a JSON literal past the double range) is NonFinite, with its path or position.

Dependencies ​

The encoders are optional and outside the default build: serde (derive), serde_json and ciborium are enabled only by the serde feature. All are pure Rust and permissively licensed (serde, serde_json: MIT or Apache-2.0; ciborium: Apache-2.0, its half dependency MIT or Apache-2.0); ciborium was already in the lockfile through the benchmark harness. glam's serde feature supplies the vector and transform impls. No internal dependency edge and no closure profile changes: serde is external, and every allowlisted internal edge stays as it was.

axiolid-core, axiolid-linear, axiolid-curve, axiolid-surface, axiolid-profile, axiolid-primitive, axiolid-mesh, axiolid-topology and axiolid-model each gain a serde feature; the facade's serde feature forwards to whichever of them are in the build.

Alternatives considered ​

OptionWhy not
Skip unknown node kindsReturns incomplete geometry silently, the failure this project exists to refuse.
Accept a newer minor and refuse only if an unknown name appearsSound only if every minor change is a new name. A minor change may also add an optional field whose absence an older reader would misread; the version is the only reliable signal.
Tolerate unknown fieldsAn older reader would drop data it was handed; failing closed matches ADR 0039.
A Rust-specific binary layout (bincode, postcard)No mature reader in JavaScript, Python, C or .NET; CBOR has one in each.
A schema language (Protocol Buffers, FlatBuffers)Pulls a code generator and a second source of truth into a format-neutral crate; the serde data model already is the schema, and the golden payloads pin it.
Explicit #[serde(rename)] on every variant and field nowHundreds of attributes repeating the Rust names. The golden payloads catch a rename that changes the wire, and the rename attribute is added then.
Hand-written wire mirror typesA second copy of every representation type to keep in step; the derive plus golden files gives the same guarantee.
Serialise non-finite numbers in CBOR onlyThe two encodings would no longer carry the same set of graphs.
Require float items for reals in CBORRefuses what common JavaScript and Python encoders write for whole numbers, though the conversion is lossless; JSON already accepts integers.
Round any CBOR integer to the nearest doubleChanges the geometry silently past 2^53.

Consequences ​

Positive

  • A host in any language can read and write the exact graph with an off-the-shelf JSON or CBOR library.
  • A breaking wire change cannot land unnoticed: the golden payloads and the variant-coverage test fail.
  • A reader never returns a partial graph.

Negative / costs

  • A wire name is now frozen beside each Rust name; renaming a variant costs a serde(rename) attribute.
  • Reading parses the envelope header before the graph, and the CBOR reader decodes to a value tree and maps it onto the JSON data model first (checking finiteness and integer exactness), so reading costs more than one pass.
  • An integer -0 does not exist, so a host that writes -0.0 as an integer zero reads back +0.0.
  • A graph holding a non-finite number, which the builder accepts, cannot be written.

Follow-ups / risks to watch

  • A glam upgrade that changed its serde layout would change the wire; the golden payloads catch it, and the old layout is then kept by hand.
  • Very deep nesting (a long Profile::Derived chain, a deeply nested piecewise law) is limited by the decoders' recursion limits and refused as Malformed.

Relation to existing code ​

  • crates/representations/modeling/graph/src/wire.rs: the envelope, FORMAT_NAME, FORMAT_VERSION, WireError, to_json, from_json, to_cbor, from_cbor.
  • crates/representations/modeling/graph/src/id.rs: node references serialise as indices and deserialise only under a graph payload.
  • crates/representations/modeling/graph/tests/wire.rs and tests/wire/: round trips over every node kind and variant, golden payloads, refusals.
  • The serde features of the representation crates listed above.

Note 2026-10-10: format 1.1 (#294) ​

Format 1.1 adds one optional field, OrientedCurveStation.seam_window (ADR 0082's #294 amendment), so FORMAT_VERSION is 1.1, a minor change under the version rules above: its absence means what a 1.0 payload meant, a window of 0.

  • Written only when it says something. The field is a real, not an Option, and the writer omits it at +0.0 instead of writing null: a graph without windows writes exactly the 1.0 graph (only the envelope's version differs), so the 1.0 golden payloads read and write back unchanged, which is this record's regression guard. -0.0 is written, so reals still round-trip bit-exactly. This is the rule for an optional field whose absence means a default value rather than "absent".
  • Read in every 1.x payload. A missing window reads as 0; a 1.0 payload that nevertheless holds a non-zero window is refused as UnknownField { field: "seam_window", version: 1.0 }, since no 1.0 writer wrote one (a window of +0.0 written into a 1.0 payload means its absence and is not told apart). A negative or non-finite window is refused by validation (InvalidGraph), as when the node is pushed.
  • Golden payloads. tests/wire/v1.0/ stays as published and is read by today's reader to the identical graph; tests/wire/v1.1/every-kind.json adds two windowed stations (an oriented station and the station of an InstanceAtStation) and is what today's writer writes.
  • Probe. scripts/probe_seam_window_mutants.py writes a zero window and reads a window in a 1.0 payload; both are caught.

Note 2026-10-10: the lowest version that represents a payload (#297) ​

The 1.1 writer of 0.3.9 labelled every payload 1.1, though a graph without windows is exactly a 1.0 graph, so a 0.3.8 reader refused every payload by its version. The version rules gain a writer rule:

  • A writer labels each payload with the lowest version that represents it, not with FORMAT_VERSION. A payload that uses nothing a minor added is written exactly as that minor's predecessor wrote it, so an older reader of the same major keeps reading everything that does not use newer features; only a payload that does is refused by an older reader, by its version. FORMAT_VERSION is the newest version a reader reads and a writer may write.
  • One feature test per minor. wire::required_version starts at 1.0 and raises the version for each feature a later minor added that the graph uses; 1.1's test is a seam-snapping window that is written (any window but +0.0, so -0.0 too) on any oriented station, found through one match naming every node kind (today an OrientedCurveStation node and the station of an InstanceAtStation). The reader's refusal of a 1.1 field in a 1.0 payload uses the same test, so a writer never labels a payload with a version whose reader would refuse it. Every future minor adds its test there.
  • Guards. Each published version's every-kind.json golden payload is written back byte for byte under its own version, JSON and CBOR alike (the 1.0 one is what 0.3.8 wrote), and a test gives each oriented station of the every-kind fixture a window in turn, found by its fields in the payload rather than by node kind, and requires 1.1 for each. scripts/probe_graph_wire_mutants.py always writes FORMAT_VERSION, and scripts/probe_seam_window_mutants.py ignores the window in one carrier or the other; each is caught.

Note 2026-10-12: format 1.2 (#301) ​

Format 1.2 adds seam sides and windows on run stations (ADR 0082's #301 amendment), so FORMAT_VERSION is 1.2, a minor change under the version rules above.

  • What it adds. Two optional fields on SectionAtStation (the sections of SectionsAtStations and OpenSectionsAtStations), seam and seam_window, omitted when they are Outgoing and +0.0 and read so when absent; and one variant, CurveRelation::OffsetsAtStations, whose RunStation { station, seam, seam_window } omit the same two fields at the same defaults. -0.0 is written, so it needs 1.2 too.
  • Its feature test (#297's rule). wire::required_version raises the version to 1.2 when a node is an OffsetsAtStations (the variant itself, even with default stations, since a 1.1 reader does not know it) or holds a section at a station whose side or window is written. The sections are found by one match naming every node kind and every variant of the relations and operations, so a new carrier cannot be added without deciding. The reader refuses the same test in a 1.0 or 1.1 payload, as such a reader would: UnknownKind { kind: "OffsetsAtStations" }, or UnknownField { field: "seam" | "seam_window" }. A graph that uses nothing 1.2 added is written exactly as before, labelled 1.0 or 1.1.
  • Golden payloads. tests/wire/v1.0/ and v1.1/ are read and written back byte for byte under their own versions; tests/wire/v1.2/every-kind.json adds two OffsetsAtStations (one with a side and a window, one with neither) and sections with a window alone, a side alone and both, and is what today's writer writes.
  • Guards. A test gives every plain station of the every-kind fixture, and every object holding one, a window (0.25, -0.0) and a side in turn, found by shape in the payload rather than by node kind: exactly the sections of SectionsAtStations and OpenSectionsAtStations accept them, each lifting the payload to 1.2 (JSON and CBOR) and each refused in a 1.1 payload; every other station refuses them as unknown fields. scripts/probe_seam_window_mutants.py breaks the 1.2 refusal, the label, the variant's test, a section's side, a -0.0 window and each carrier; each is caught.

Note 2026-10-13: format 1.3 (#303) ​

Format 1.3 adds run stations at their basis's ends (ADR 0082's #303 amendment), so FORMAT_VERSION is 1.3, a minor change under the version rules above.

  • What it adds. One optional field on RunStation (the stations of CurveRelation::OffsetsAtStations), basis_end, "Start" or "End", omitted when absent (a stated distance) and read so. Such a station writes its distance 0, which validation requires.
  • Its feature test (#297's rule). wire::required_version raises the version to 1.3 when a run station writes basis_end. The run stations are found by one match naming every node kind and every variant of the curve relations, so a new carrier cannot be added without deciding. The reader refuses the same test in a 1.2 payload as UnknownField { field: "basis_end" } (an older payload refuses OffsetsAtStations itself by kind). A graph that uses nothing 1.3 added is written exactly as before, labelled 1.0, 1.1 or 1.2.
  • Golden payloads. tests/wire/v1.0/ to v1.2/ are read and written back byte for byte under their own versions; tests/wire/v1.3/every-kind.json adds an OffsetsAtStations from its basis's start to its end (the end with a window), and is what today's writer writes.
  • Guards. A test gives every plain station of the every-kind fixture, and every object holding one, basis_end ("Start", "End") in turn, found by shape in the payload: exactly the run stations of OffsetsAtStations accept it (refused by validation where their place in the run is wrong), each placement that validates lifting the payload to 1.3 (JSON and CBOR) and refused in a 1.2 payload; every other station refuses it as an unknown field. scripts/probe_run_basis_end_mutants.py writes an absent end, reads one in a 1.2 payload, never labels 1.3 and ignores the carrier; each is caught.

Note 2026-10-13: exact JSON reals need correctly rounded parsing ​

The bit-exact promise for reals holds only if the JSON reader rounds correctly. serde_json's default fast parser does not: it lands one ulp off for about a quarter of ordinary doubles. The workspace therefore enables serde_json's float_roundtrip feature, and a test sweeps 6,000 doubles across twenty magnitudes through JSON and CBOR. A host reading these payloads in another language needs a correctly rounded decimal parser (most standard libraries have one, such as JavaScript's Number or Python's float).

Note 2026-10-16: format 1.4 (#321) ​

Format 1.4 adds a half-space bounded along its placement's z, so FORMAT_VERSION is 1.4, a minor change under the version rules above. The triage first chose a field on BoundedHalfSpace; the maintainer then chose a new variant instead (#321's triage update), because a field on a public struct variant breaks the Rust API and would have forced axiolid-model 0.4.0. SolidOperation is #[non_exhaustive], so a variant is additive. Every graph written before keeps its meaning.

  • What it adds. One variant, SolidOperation::BoundedHalfSpaceAlongZ, with BoundedHalfSpace's fields (half_space, boundary, placement): the boundary's prism runs along the placement's z, oblique to the plane allowed, as IFC's IfcPolygonalBoundedHalfSpace does, where BoundedHalfSpace's runs along the plane's normal.
  • Its feature test (#297's rule). wire::required_version raises the version to 1.4 when a node is a BoundedHalfSpaceAlongZ. The reader refuses the same test in a 1.3 or older payload as UnknownKind { kind: "BoundedHalfSpaceAlongZ" }, as such a reader would. A graph without the variant is written exactly as before, labelled 1.0 to 1.3.
  • Golden payloads. tests/wire/v1.0/ to v1.3/ are read and written back byte for byte under their own versions; tests/wire/v1.4/every-kind.json adds a BoundedHalfSpaceAlongZ, and is what today's writer writes.
  • Guards. A test restates every BoundedHalfSpace of the every-kind fixture, its 1.4 content taken out, as BoundedHalfSpaceAlongZ in turn: each reads in place, lifts the payload to 1.4 (JSON and CBOR), and is refused in a 1.3 payload. The builder validates the new variant's references as the old one's. scripts/probe_prism_axis_mutants.py reads the variant in a 1.3 payload, never labels 1.4 and skips its references; each is caught.

Note 2026-11-03: format 1.5 (#402) ​

Format 1.5 adds a surface ruled between two sides, so FORMAT_VERSION is 1.5, a minor change under the version rules above. SurfaceRelation is #[non_exhaustive], so the variant is additive. The variant's design is ADR 0097.

  • What it adds. One variant, SurfaceRelation::Ruled { first, second }, and the enum RuledSide: a Curve { curve, interval } (an atomic Curve3 node over an oriented interval) or an Apex point.
  • Its feature test (#297's rule). wire::required_version raises the version to 1.5 when a node is a Ruled. The reader refuses the same test in a 1.4 or older payload as UnknownKind { kind: "Ruled" }, as such a reader would. A graph without the variant is written exactly as before, labelled 1.0 to 1.4.
  • Golden payloads. tests/wire/v1.5/every-kind.json adds two ruled surfaces and is what today's writer writes.
  • Guards. A test reinstates each ruled surface of the every-kind fixture in turn over the fixture with its 1.5 content taken out: each reads, lifts the payload to 1.5 (JSON and CBOR), and is refused in a 1.4 payload. A ruled surface read is validated as one built in memory. scripts/probe_ruled_surface_mutants.py reads the variant in a 1.4 payload and never labels 1.5; each is caught.

Released under the Mozilla Public License 2.0.