christophhagen / BinaryCodable

A binary encoder for Swift Codable types
MIT License
92 stars 7 forks source link

UUID fails to decode #7

Closed sgjsgj closed 1 year ago

sgjsgj commented 1 year ago

This simple use case works with JSON encoder but fails with BinaryCodable. Seems to be a problem with UUID -- it works if I use a string instead. Did I miss something or is this an issue?

enum MyEnum: Codable {
    case test(UUID)
}
let test = MyEnum.test(UUID())
let encoded = try BinaryEncoder().encode(test)
// The following throws BinaryCodable.BinaryDecodingError.prematureEndOfData:
let decoded = try BinaryDecoder().decode(MyEnum.self, from: encoded)
christophhagen commented 1 year ago

Yes, this is an issue.

There are currently several issues related to incorrect decoding. The library is undergoing significant changes at the moment to fix these. I would recommend to switch to a different library, like PotentCodables and CBORCoding, if you don't depend on this one yet.

christophhagen commented 1 year ago

This issue was related to other encoding problems around optionals. The new release 2.0.0 should fix the issue (there are additional unit tests for UUID now). The binary format was changed with the new release, so there's limited backward compatibility.