Revise Codable?

Hi guys. Half a year ago I was told that we can't change Codable for Swift 5, but I've decided to show how much more flexible we could make it, and maybe.. we still can?

This changes allows us to write superfast raw coders on top of UnsafeRawBufferPointer or Substring without extra allocations and without classes at all. And we can use anything as CodingKey not just String / Int.

I don't think it'll pass so here the link: Revise Codable

I'll finish the implementation if anyone else is interested.

13 Likes

Thanks for this, @tonyfreeman.

I too wish that Encoder.container(keyedBy:), unkeyedContainer(), and singleValueContainer() could throw.

Look at this behemoth, almost 100 lines of workaround: https://github.com/groue/GRDB.swift/blob/v3.5.0/GRDB/Record/PersistableRecord%2BEncodable.swift#L221-L317

The good news is that adding the throws qualifier to those methods would not break any code :-)

Terms of Service

Privacy Policy

Cookie Policy