Reputation: 17555
I'm writing a C# application, where objects are to be identified by their Guid
. According to the customer, there should be two types:
I believe that the System.Guid
corresponds with the first one: System.Guid
consists of one int
(32-bit), two short
s (each 16-bit) and eight byte
s (each 8 bits), which comes together to 32 + 2*16 + 8*8 = 128
bits.
But as far as the so-called IFC64 GUID
, I don't find anything.
Does anybody know in which C# library this is defined?
Thanks in advance
Upvotes: 2
Views: 249
Reputation: 369
Xbim Toolkit has C# helper methods to translate between .net Guids and Ifc's encoded Guid. See https://github.com/xBimTeam/XbimEssentials/blob/master/Xbim.Ifc4/UtilityResource/IfcGloballyUniqueIdPartial.cs
Upvotes: 1
Reputation: 536
You are looking for IfcOpenShell: https://github.com/IfcOpenShell/IfcOpenShell
Good implementation of expander-compressor for IFC GIDs here: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcopenshell-python/ifcopenshell/guid.py
Upvotes: 2
Reputation: 1331
The IFC GUIDs are 128 bit long (not 132 bit!), same as other UUIDs. When represented in text, IFC GUIDs are encoded using radix 64 and a 64-character alphabet (see below). This is used similar to the standard hexadecimal representation, but omits the dashes and uses a larger base, such that it is more compact than hexadecimal representation.
Note that contrary to the Base64 encoding method for arbitrary binary data to text aligned left and with right-side padding, the IFC radix 64 encoding is producing a base 64 number aligned right with left-side padding. Thus, since every digit is 6 bits and 128 has a reminder of 2 when divided by 6, the first (most significant) digit is always 0, 1, 2 or 3.
Here is some C# code to illustrate:
String charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$";
var hexUuid = Guid.NewGuid().ToString().Replace("-", "");
Console.WriteLine("Hex: " + hexUuid);
var numUuid = BigInteger.Parse("0" + hexUuid, NumberStyles.AllowHexSpecifier);
Console.WriteLine("Dec: " + numUuid);
var ifcUuid = Enumerable.Range(0,22).Select(i => charset[(int)((numUuid >> (i*6)) & 63)]).Reverse();
Console.WriteLine("IFC: " + string.Join("", ifcUuid));
Upvotes: 1