Module guid

Module guid 

Source
Expand description

The IfcGloballyUniqueId (22-char GlobalId) home: alphabet, validators, the leading-GlobalId reader and the two deterministic minters.

Two notions on purpose, NOT interchangeable (#7777): is_global_id_shaped (length + alphabet) decides whether a token is RECOGNISED as a GlobalId, so the merge sees every collision real files produce (some exporters write a first character outside 0..=3); is_valid_global_id additionally enforces the 128-bit packing rule and gates what we WRITE or trust (appearance). Strictness must never decide whether a collision is seen.

Constants§

ALPHABET
buildingSMART base64 alphabet (64 chars) used by IfcGloballyUniqueId.

Functions§

decode_bits
The 128 bits a GlobalId encodes: the inverse of encode, or None when s is not is_valid_global_id (a first character past '3' would need a 129th bit). A GlobalId is a compressed GUID, so these bits are the GUID a tool that expands GlobalIds (IfcOpenShell’s guid.expand) prints.
deterministic
Deterministic 22-char GlobalId from an arbitrary seed. A faithful port of @ifc-lite/parser’s deterministicGlobalId (four independent 32-bit rolling hashes cross-mixed into a 128-bit state, stamped MSB-first as 2 + 21*6 bits), pinned by rust/export/tests/fixtures/deterministic_global_id_vectors.json.
encode
Encode 128 bits as an IfcGloballyUniqueId: 22 characters of ALPHABET, read MSB-first. 22 x 6 = 132 bits is four more than a GUID holds, so the FIRST character carries only the top 2 bits (0..3) and each of the other 21 carries 6. That split is the IFC convention, not RFC 4648 base64: a different alphabet order, no padding, and no byte alignment.
hash128
The 128-bit state deterministic encodes, exposed so a caller that needs the bits (to derive further ids from them) gets the same hash rather than a second one.
is_global_id_shaped
True for a 22-char token drawn entirely from ALPHABET (^[0-9A-Za-z_$]{22}$). Does not check the first-character range.
is_valid_global_id
is_global_id_shaped plus the spec rule that the first character carries only 2 bits ('0'..='3'), since 22 chars hold 2 + 21 * 6 = 128 bits.
leading_global_id
The first '...' string of a STEP entity line, when it is GlobalId-shaped. Only the first 128 bytes are inspected. Rootedness (whether the entity type has a GlobalId at all) is the caller’s decision.
placeholder
Deterministic 22-char GlobalId-shaped placeholder derived from an express id (right-aligned base-64 of id + 0x1000_0000, zero-padded). Intentionally NOT the TypeScript mint: schema conversion pins this divergence (schema_convert_tests.rs).
read_leading_global_id
Rendered-line reader used by the merge’s collision bookkeeping: the first '...' after the first (, anywhere in the text (no window), when it is GlobalId-SHAPED. Deliberately the lenient is_global_id_shaped test, not is_valid_global_id: whether a collision is SEEN must never depend on validity, or two entities sharing a non-conforming id are silently kept.
replace_rendered_global_id
text with the string read by read_leading_global_id’s scan replaced by new_guid; unchanged when the line has no quoted first attribute.