Skip to content

Commit

Permalink
[swift] Better handling for edge case field names
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Oct 18, 2023
1 parent c8500e4 commit e0213bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions wire-tests-swift/no-manifest/src/main/swift/SwiftEdgeCases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public struct SwiftEdgeCases {
@ProtoDefaulted
public var `return`: String?
@ProtoDefaulted
public var string: String?
public var type: String?
public var unknownFields: Foundation.Data = .init()

public init(configure: (inout Self) -> Swift.Void = { _ in }) {
Expand All @@ -22,9 +22,9 @@ extension SwiftEdgeCases {

@_disfavoredOverload
@available(*, deprecated)
public init(`return`: Swift.String? = nil, string: Swift.String? = nil) {
public init(`return`: Swift.String? = nil, type: Swift.String? = nil) {
self._return.wrappedValue = `return`
self._string.wrappedValue = string
self._type.wrappedValue = type
}

}
Expand Down Expand Up @@ -64,25 +64,25 @@ extension SwiftEdgeCases : Proto2Codable {

public init(from protoReader: Wire.ProtoReader) throws {
var `return`: Swift.String? = nil
var string: Swift.String? = nil
var type: Swift.String? = nil

let token = try protoReader.beginMessage()
while let tag = try protoReader.nextTag(token: token) {
switch tag {
case 1: `return` = try protoReader.decode(Swift.String.self)
case 2: string = try protoReader.decode(Swift.String.self)
case 2: type = try protoReader.decode(Swift.String.self)
default: try protoReader.readUnknownField(tag: tag)
}
}
self.unknownFields = try protoReader.endMessage(token: token)

self._return.wrappedValue = `return`
self._string.wrappedValue = string
self._type.wrappedValue = type
}

public func encode(to protoWriter: Wire.ProtoWriter) throws {
try protoWriter.encode(tag: 1, value: self.`return`)
try protoWriter.encode(tag: 2, value: self.string)
try protoWriter.encode(tag: 2, value: self.type)
try protoWriter.writeUnknownFields(unknownFields)
}

Expand All @@ -94,14 +94,14 @@ extension SwiftEdgeCases : Codable {
public init(from decoder: Swift.Decoder) throws {
let container = try decoder.container(keyedBy: Wire.StringLiteralCodingKeys.self)
self._return.wrappedValue = try container.decodeIfPresent(Swift.String.self, forKey: "return")
self._string.wrappedValue = try container.decodeIfPresent(Swift.String.self, forKey: "string")
self._type.wrappedValue = try container.decodeIfPresent(Swift.String.self, forKey: "type")
}

public func encode(to encoder: Swift.Encoder) throws {
var container = encoder.container(keyedBy: Wire.StringLiteralCodingKeys.self)

try container.encodeIfPresent(self.`return`, forKey: "return")
try container.encodeIfPresent(self.string, forKey: "string")
try container.encodeIfPresent(self.type, forKey: "type")
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ package squareup.protos.kotlin.swift_modules;

message SwiftEdgeCases {
optional string return = 1;
optional string string = 2;
optional string type = 2;
}

0 comments on commit e0213bb

Please sign in to comment.