emraz
emraz

Reputation: 1613

How to convert UUID into 16 bytes UInt8 array in MacOS Objective C / C++

I can get UUID string using below code ..

CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);

Or I can get bytes using below code

CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFUUIDBytes bytes = CFUUIDGetUUIDBytes(theUUID);

But I would like to make an array of UInt8 and as the UUID is 16 bytes, so the output array should be in 16 bytes.

Upvotes: 1

Views: 1053

Answers (1)

David Hoerl
David Hoerl

Reputation: 41632

By examining the CFUUIDBytes typedef you can see how to access each byte:

CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFUUIDBytes bytes = CFUUIDGetUUIDBytes(theUUID);

UInt8 rawData[16];
rawData[0] = bytes.byte0;
rawData[1] = bytes.byte1;
...
rawData[15] = bytes.byte15;

Upvotes: 2

Related Questions