Jump to content
Lars Fosdal

Is there a Delphi lib that can generate an RFC-4122 UUID?

Recommended Posts

Have you looked yet at RFC-4122?

https://datatracker.ietf.org/doc/html/rfc4122

The document you cite only hits a few points. One issue it raises is that of case, but in the small quote from the RFC, it does point out that although the UUID is output as lower case, it is case insensitive at input. Awkward wording, but I would take that to mean that the UUID is to be read in a case-insensitive fashion, whereas "input" could be interpreted to mean "from the keyboard" or other device. 

 

The RFC offers an example of a properly formatted UUID: 

urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6

It seems obvious that the issue of case should never be allowed to interfere, given that the alpha characters relate only to hex values.

 

As to your question about a library, I don't know whether one exists. But given that Delphi inserts a GUID for you in this form:

['{480BE84A-F629-4A7C-BC94-4FC06A2E03BA}']

Then by stripping off the leading and trailing braces and brackets and converting to lower case, you would have an RFC-4122 conformant UUID which is of the form specific to MS.

 

And for what it may be worth, I think the author made a poor choice enumerating the four types starting at 1, when the RFC lends itself more naturally to a zero-based reference. 

 

In the end, I suppose I should respond to your question with "what do you mean by that?" We could argue the semantics of descriptions, but in the end, the GUID conforms - per the RFC - to the MS variant rules, and the UUID subsumes the GUID.

 

Edited by Bill Meyer

Share this post


Link to post

The RFC describes four variant formats, and the MS GUID is variant 2.
I am simply wondering if there is another implementation than the MS one available to me in case the MS one is not compatible with IBMs requirements.

uses
  System.SysUtils;

var
  guid: TGuid;
  sguid: string;
begin
  if CreateGUID(guid) = S_OK
   then sguid := 'urn:uuid:' + guid.ToString.ToLower;

 

  • Thanks 1

Share this post


Link to post

Since variants 0 and 3 are reserved, then there really are only two variants. But there are still variabilities in Version.

 

I'd wait to see the spec from IBM, and start be determining whether you can use the existing GUID support with some minor string manipulation afterward. Too many unknowns if you haven't seen their spec.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×