openbim_ifc_binding_core/value.rs
1//! The lossless tagged value encoding (ADR 0013).
2//!
3//! Every IFC attribute value crosses to JavaScript as an object with a `kind`
4//! field, plus a payload field that depends on the kind:
5//!
6//! | `kind` | payload | STEP example |
7//! | --------- | ----------------------- | ---------------------- |
8//! | `null` | — | `$` |
9//! | `derived` | — | `*` |
10//! | `bool` | `value: boolean` | `.T.` / `.F.` |
11//! | `unknown` | — | `.U.` |
12//! | `integer` | `value: bigint` | `42` |
13//! | `real` | `value: number` | `2.5` |
14//! | `text` | `value: string` | `'Wall'` |
15//! | `binary` | `value: string` (hex) | `"0123ABC"` |
16//! | `enum` | `value: string` | `.ELEMENT.` |
17//! | `ref` | `id: bigint` | `#42` |
18//! | `list` | `items: Value[]` | `(1,2)` |
19//! | `typed` | `type: string, value: Value` | `IFCLABEL('x')` |
20//!
21//! Integers and ids are `bigint` because IFC integers are 64-bit and a JS
22//! number loses precision above 2^53. `unknown` is its own kind rather than
23//! `bool` with a null value so that no JS truthiness check can confuse it
24//! with `.F.`.
25//!
26//! The table names the JavaScript fields; Python and C carry the same kinds
27//! and payloads in their own idiom. [`Tagged`] is the host-independent form:
28//! each binding only moves `Tagged` into and out of host values, so the
29//! mapping itself is tested once, natively.
30
31mod tagged;
32
33pub use tagged::{Kind, Tagged};
34
35/// Deepest list or typed-wrapper nesting accepted from a host.
36///
37/// Matches the STEP parser's limit, so any value the parser can produce can
38/// round-trip, while a hostile deeply nested object cannot overflow the stack.
39pub const MAX_NESTING: usize = 128;