ifc_lite_processing/processor/
schema_detection.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use ifc_lite_core::SchemaFamily;
6
7/// The IFC schema a STEP file declares: `"IFC2X3"`, `"IFC4"`, `"IFC4X3"` or
8/// `"IFC5"`. THE detector for every `schema_version` this workspace reports,
9/// the native pipeline's `ModelMetadata` and the server's `/parse/metadata`
10/// alike (PROCESSING-5 / SERVER-18, #7691: the server kept a second,
11/// case-sensitive copy, and processing searched the whole file, so `ifc4`
12/// inside a GUID reported an IFC2X3 model as IFC4).
13///
14/// The rule is the TS parser's `detectSchemaVersion`
15/// (`packages/parser/src/source-header.ts`), pinned against it by the shared
16/// vectors in `rust/core/tests/fixtures/schema_version_vectors.json`:
17/// 1. The first `FILE_SCHEMA` identifier that names a family wins
18///    ([`SchemaFamily::detect`], over `first_declared_schema`, the selection
19///    the decoder's attribute layout uses too). The header reader is quote-
20///    and comment-aware, so text in DATA, header strings or comments does not
21///    count.
22/// 2. If none does (no, empty or unparseable declaration), the first 2000
23///    bytes are searched for a schema token, ASCII case-insensitively. This
24///    is a loose last resort: with no declaration it can match `ifc4` inside
25///    a GUID in those bytes, exactly as the TS twin does (pinned by a shared
26///    vector, #7740).
27/// 3. Otherwise `"IFC4"`.
28pub fn detect_schema_version(content: &[u8]) -> &'static str {
29    SchemaFamily::detect(content).unwrap_or(SchemaFamily::Ifc4).as_str()
30}
31
32#[cfg(test)]
33#[path = "schema_detection_tests.rs"]
34mod tests;