Skip to content

Instantly share code, notes, and snippets.

@jen20
Last active October 14, 2019 12:28
Show Gist options
  • Save jen20/781ced3a722481c9f223 to your computer and use it in GitHub Desktop.
Save jen20/781ced3a722481c9f223 to your computer and use it in GitHub Desktop.
var order = [...]int{3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15}
func wtfToUUID(netEncoded []byte) uuid.UUID {
uuidBytes := make([]byte, 16)
for i := 0; i < len(order); i++ {
uuidBytes[i] = netEncoded[order[i]]
}
return uuidBytes
}
//using the UUID type from "code.google.com/p/go-uuid/uuid"
private static final int[] mostOrder = new int[]{3,2,1,0,5,4,7,6};
private static UUID uuidFromWtf(byte[] dotNetEncodedGuid) {
long most = 0;
long least = 0;
for (int i : mostOrder) {
most = (most << 8) | (dotNetEncodedGuid[i] & 0xFF);
}
for (int i = 8; i < 16; i++) {
least = (least << 8) | (dotNetEncodedGuid[i] & 0xFF);
}
return new UUID(most, least);
}
@bmavity
Copy link

bmavity commented Feb 8, 2016

Hi,

How can I tell if this is necessary for https://github.com/bmavity/ges-client ?

@jen20
Copy link
Author

jen20 commented Mar 25, 2016

Sorry only just saw this - it is almost certainly required outside of the CLR and perhaps the windows API.

@gregoryyoung
Copy link

it is.

@gregoryyoung
Copy link

maybe node does the same? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment