google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.26k stars 362 forks source link

Add parsing support for braced and non-dashed string forms #24

Closed JoshuaSjoding closed 6 years ago

JoshuaSjoding commented 6 years ago

I would like to prepare and submit a pull request that adds parsing support for two string forms that are not RFC-4122 compliant:

Braced

{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

Non-dashed

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The first is commonly generated by APIs and tools on the Windows platform.

The second is the hexadecimal encoding of the uuid without any further treatment.

Both assume the hexadecimal values to be in big-endian order, as per the spec. Any platform-specific byte-reordering would be left to the user.

The form of an input string can quickly be determined by its length, and the lengths are unique so parsing remains deterministic.

JoshuaSjoding commented 6 years ago

Both Parse and ParseBytes would be affected by this. I would refactor both functions to avoid repetition, and modify the test suite to include the new forms.

pborman commented 6 years ago

Would you be willing to make the same changes to pborman/uuid? These are essentially the same packages with the exception that the google one has:

type UUID [16]byte

while the (older) pborman one has:

type UUID []byte

At some point I should make one of these be implemented in terms of the other, but that will make one of them slightly slower.

pborman commented 6 years ago

github.com/pborman/uuid is being modified to leverage this package (it is the same code). I would like to see if there are any other common formats for UUIDs.

pborman commented 6 years ago

JoshuaSjoding@, would you care to do a code review of https://github.com/google/uuid/pull/37