struct ExampleOneOf: Codable {
let field1: Int32
// The oneof field
let alternatives: Alternatives
// The OneOf definition
enum Alternatives: Codable, ProtobufOneOf {
case id(Int64)
case name(String)
// Field values, must not overlap with `ExampleOneOf.CodingKeys`
enum CodingKeys: Int, CodingKey {
case id = 2
case name = 3
}
}
enum CodingKeys: Int, CodingKey {
case field1 = 1
// The field id of the Oneof field is not used
case alternatives = 123456
}
}
Adds support to encode and decode protobuf Oneof types.
A new protocol
ProtobufOneOf
signals that enums with associated values should be treated as aOneof
on the wire.A protobuf definition of a
oneof
:The corresponding Swift definition would be: