Domanda

For my distributed storage keys I want to use UUID v4, and .NET Framework's System.Guid gives me exactly that. However, I cannot test right now if Mono gives the same v4? Is there a standalone v4 generator in C#/F#? Is there a spec that says that .NET/Mono GUID is always version 4? (googled, couldn't find)

Additionally, I want to do some hack with GUID v4. Given that the format of it is xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, I want to replace the 4 with a custom HEX number. I need this to embed a kind of epoch info when my GUIDs was generated in my system, and I know that the max number of epochs will never reach HEX f.

The question is if that is safe and future proof? Are you aware of any software that somehow validates Guids in a way other than 'it must be some 128 bits'? I am afraid that putting e.g. 5 instead of 4 could break something in, e.g. PostgreSQL uuid column type or in some similar situation. And I cannot test all cases where that could happen. I tested all numbers instead of 4 with System.Guid.Parse() and it works OK, but I do not know if that is by luck or by spec.

È stato utile?

Soluzione

According to the UUID specs at http://www.ietf.org/rfc/rfc4122.txt

I quote (this is under the v4 section):

Conformance with URN Syntax: The string representation of a UUID is fully compatible with the URN syntax. When converting from a bit-oriented, in-memory representation of a UUID into a URN, care must be taken to strictly adhere to the byte order issues mentioned in the string representation section.

Validation mechanism: Apart from determining whether the timestamp portion of the UUID is in the future and therefore not yet assignable, there is no mechanism for determining whether a UUID is 'valid'.

** I presume that if no validation is possible, no software should complain about your manually generated UUID, as long as the timestamp is future

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top