1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//! Frame-document schema: the self-describing serialized form of an
//! astrodyn reference-frame tree.
//!
//! This crate carries **only** the document types and their (de)serialization
//! — no physics. A read-only consumer (renderer, logger, analyzer) links this
//! crate (plus the identity vocabulary in `astrodyn_quantities`) and can
//! interpret a recorded run without the producer's code (spec RFS-602,
//! [Spec-Reference-Frame-Requirements](https://github.com/simnaut/astrodyn/wiki/Spec-Reference-Frame-Requirements)).
//!
//! ## Document model
//!
//! Two forms share one record vocabulary:
//!
//! - [`FrameDocument`] — a **snapshot**: header + interned [`FrameUid`]
//! table + one [`FrameRecord`] per frame node.
//! - [`FrameSeries`] — **replay v1**: header + uid table + a sequence of
//! [`FrameSegment`]s, each holding per-epoch record rows. A segment spans
//! a constant topology; any topology change (a frame-switch reparent, an
//! attach) closes the segment, so segment boundaries double as seek
//! keyframes. Streaming topology events are replay v2 (issue #663 scope).
//!
//! **Every state record names the parent uid it is relative to** — snapshot
//! and series alike. Consumers check their folded topology against each
//! record's declared parent, so a missed or misordered topology change is a
//! loud inconsistency, never silent misinterpretation.
//!
//! Per record, state carries its **origin** (RFS-603): `Integrated`
//! (authoritative body store — the tree node is a per-step projection),
//! `Derived` (re-derivable from a model id + the record epoch), or
//! `Injected` (caller-supplied ground truth). Rotation is serialized as
//! [`CanonicalRotation`] — whichever representation was canonical at the
//! write site (the typed path is quaternion-canonical per JEOD_INV RF.04;
//! rotation-model writers like `sync_pfix_rotation` are matrix-canonical) —
//! and the other representation is re-derived on load, which is what makes
//! serialize → reload → continue bit-identical for both regimes (RFS-601).
//!
//! ## Encoding
//!
//! Plain-decimal JSON. Shortest-round-trip float printing makes `f64`
//! round-trips bit-exact (proven by this crate's full-entropy property test
//! and the `cartesian_state_json_round_trips_bit_exact` precedent in
//! `astrodyn_quantities`). Non-finite values are rejected loudly at
//! serialize time — a NaN in a frame document is upstream broken physics,
//! not data. A binary form is a later, additive decision.
//!
//! The header carries the schema version and the numeric conventions
//! **in-band** ([`Conventions`]); [`FrameDocument::validate`] checks them
//! before any state is interpreted, so a consumer that never links astrodyn
//! cannot silently misread a changed convention.
//!
//! ## Per-record / streaming consumers
//!
//! The record types — [`DocHeader`], [`FrameRecord`], [`EpochRow`],
//! [`FrameUid`] and their components — are a **supported, stable surface**
//! for independent serialization, not internals behind the whole-document
//! JSON API. `to_json_string` / `from_json_str` are conveniences over the
//! same `serde` derives; a live feed may serialize records individually
//! (e.g. a binary serde format over a socket) under these rules:
//!
//! - **Handshake = header + uid table.** Records reference identities
//! positionally (`FrameRecord::uid_index` / `parent` index into the
//! interned `Vec<FrameUid>`), so transmit [`DocHeader`] and the uid
//! table once, then per-epoch [`EpochRow`]s. Validate the handshake
//! *before interpreting any number* via [`validate_header`] and
//! [`validate_uid_table`], and each arriving row via
//! [`validate_record`] — the loose-piece equivalents of the
//! whole-document `validate()` entry points.
//! - **Topology changes are segment boundaries.** A reparent or attach
//! changes what `parent` means; mirror replay v1's rule on a live feed
//! by re-sending header + uid table as a fresh keyframe. Per-record
//! `parent` keeps every row self-checking: verify it against your
//! folded topology and treat a mismatch as a loud inconsistency, never
//! a reinterpretation. (Cross-record invariants — cycle-freedom, row
//! completeness, constant topology within a segment — are the
//! container `validate()`s' job and become the *consumer's* job on a
//! stream.)
//! - **Format notes.** Positional formats (postcard/bincode) bind to
//! field *order*, self-describing formats to field *names*; pin this
//! crate's version on both ends and gate on
//! [`DocHeader::schema_version`] at handshake. Binary `f64` encodings
//! are inherently bit-exact — the shortest-round-trip /
//! `float_roundtrip` requirement above is JSON-specific. Non-finite
//! values remain invalid in any encoding.
//! - **Stability.** The wire schema evolves only through
//! [`SCHEMA_VERSION`]; these Rust types *are* the schema, so field
//! changes imply a version bump and a semver-visible crate change.
//! Evolution is additive where possible (enums such as [`Origin`] /
//! [`CanonicalRotation`] may gain variants behind a version bump);
//! existing fields are not silently re-shaped.
//!
//! ```
//! use astrodyn_frame_doc::{
//! validate_header, validate_record, validate_uid_table, CanonicalRotation, Conventions,
//! DocHeader, EpochRow, FrameRecord, FrameUid, Origin, TransRecord, SCHEMA_VERSION,
//! };
//! use astrodyn_quantities::frame::RootInertial;
//!
//! // ── Producer side: handshake, then rows ──
//! let header = DocHeader {
//! schema_version: SCHEMA_VERSION,
//! conventions: Conventions::current(),
//! simtime: 0.0,
//! tai_tjt_at_epoch: 11544.499257592593,
//! };
//! let uids = vec![FrameUid::of::<RootInertial>()];
//! let row = EpochRow {
//! simtime: 0.0,
//! records: vec![FrameRecord {
//! name: "root".into(),
//! uid_index: 0,
//! parent: None,
//! epoch: Some(0.0),
//! trans: TransRecord {
//! position: [0.0; 3],
//! velocity: [0.0; 3],
//! },
//! rotation: CanonicalRotation::Quat([1.0, 0.0, 0.0, 0.0]),
//! ang_vel_this: [0.0; 3],
//! origin: Origin::Injected,
//! }],
//! };
//!
//! // ── Consumer side: validate the handshake before any number, then
//! // each arriving row against the handshake's uid table. ──
//! validate_header(&header).expect("handshake header");
//! validate_uid_table(&uids).expect("handshake uid table");
//! for (pos, rec) in row.records.iter().enumerate() {
//! validate_record(rec, pos, uids.len()).expect("arriving row");
//! // ...then check rec.parent against your folded topology.
//! }
//! ```
pub use ;
pub use ;
// Re-export the identity vocabulary the wire types embed, so a document
// consumer needs only this crate in its dependency list.
pub use ;
pub