简体   繁体   中英

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM