Lorenz Brun | 62a1edd | 2023-06-20 16:01:44 +0200 | [diff] [blame] | 1 | // Package msguid provides functions to convert UUIDs/GUIDs to and from |
| 2 | // Microsoft's idiosyncratic "mixed-endian" format. |
| 3 | // See https://uefi.org/specs/UEFI/2.10/Apx_A_GUID_and_Time_Formats.html#text-representation-relationships-apxa-guid-and-time-formats |
| 4 | // for an explanation of the format. |
| 5 | package msguid |
| 6 | |
| 7 | import "github.com/google/uuid" |
| 8 | |
| 9 | var mixedEndianTranspose = []int{3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15} |
| 10 | |
| 11 | // From converts from a standard UUID into its mixed-endian encoding. |
| 12 | func From(u uuid.UUID) (o [16]byte) { |
| 13 | for dest, from := range mixedEndianTranspose { |
| 14 | o[dest] = u[from] |
| 15 | } |
| 16 | return |
| 17 | } |
| 18 | |
| 19 | // To converts a mixed-endian-encoded UUID to its standard format. |
| 20 | func To(i [16]byte) (o uuid.UUID) { |
| 21 | for from, dest := range mixedEndianTranspose { |
| 22 | o[dest] = i[from] |
| 23 | } |
| 24 | return |
| 25 | } |