Skip to main content

cadmpeg_ir/
provenance.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Provenance and exactness value types.
3//!
4//! [`Exactness`] classifies how an IR value relates to source bytes. Current
5//! documents store exactness and source locations in
6//! [`crate::annotations::Annotations`].
7
8use schemars::JsonSchema;
9use serde::{Deserialize, Serialize};
10
11use crate::topology::Color;
12
13/// Native object identity and effective display metadata for a free carrier.
14///
15/// `format` identifies the source format. `object_id` is the source format's
16/// native object identifier, not an IR arena identifier. `name`, `color`, and
17/// `visible` are the effective object display values. `layer` is the native
18/// layer identifier. `instance_path` contains native instance identifiers in
19/// outermost-to-innermost order; an empty path means that the object is not
20/// nested in an instance.
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
22pub struct SourceObjectAssociation {
23    /// Source format identifier.
24    pub format: String,
25    /// Native source object identifier.
26    pub object_id: String,
27    /// Effective source object name, when present.
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub name: Option<String>,
30    /// Effective source object color, when present.
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub color: Option<Color>,
33    /// Effective source object visibility, when present.
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub visible: Option<bool>,
36    /// Native source layer identifier, when present.
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub layer: Option<String>,
39    /// Native instance identifiers from outermost to innermost.
40    #[serde(default, skip_serializing_if = "Vec::is_empty")]
41    pub instance_path: Vec<String>,
42}
43
44/// Source location for an entity's bytes.
45///
46/// `offset` is relative to `stream`; `tag` identifies the source record class
47/// when known.
48#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
49pub struct Provenance {
50    /// Source container format.
51    pub format: String,
52    /// Named stream within the container (a decompressed entry name, or empty).
53    pub stream: String,
54    /// Byte offset of the record within `stream`.
55    pub offset: u64,
56    /// Source record/class name/tag, when the decoder can attribute one.
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    pub tag: Option<String>,
59}
60
61/// How an entity or field value was established from its source.
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
63#[serde(rename_all = "snake_case")]
64pub enum Exactness {
65    /// Read verbatim from the source stream with no transformation beyond
66    /// documented unit conversion.
67    ByteExact,
68    /// Computed deterministically from byte-exact inputs.
69    Derived,
70    /// Filled in from context or convention rather than an explicit source field.
71    Inferred,
72    /// Origin or trustworthiness could not be established.
73    Unknown,
74}