hassan-shahbazi / CBORSwift

Swift implementation for CBOR
http://cbor.io/impls.html#swift
MIT License
10 stars 1 forks source link

Request: Support for binary UUID / NSUUID #3

Closed dhiraj closed 6 years ago

dhiraj commented 6 years ago

It would be awesome if you added support for UUIDs as per https://github.com/lucas-clemente/cbor-specs/blob/master/uuid.md

I'm willing to code support myself, tried using the custom tag support as well but couldn't. Please help, thanks!

I'm able to get a UUID's representation as [UInt8] but I can't figure out what to do next after that.

hassan-shahbazi commented 6 years ago

Encoding/Decoding functions are implemented for Tagged values. In your case, you may use the following code:

let deviceUUID = UIDevice.current.identifierForVendor!.uuidString.replacingOccurrences(of: "-", with: "")
let deviceUUIDByteString = NSByteString(deviceUUID)
let tag = NSTag(tag: 37, deviceUUIDByteString)
let encoded = CBOR.encode(tag)

print(Data(bytes: encoded!).hex)

You can check the result of print.... using cbor.me tools.

dhiraj commented 6 years ago

Thanks, this is very helpful!