-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[swift] Better handling for edge case field names
- Loading branch information
Showing
4 changed files
with
136 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
wire-tests-swift/no-manifest/src/main/swift/SwiftEdgeCases.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Code generated by Wire protocol buffer compiler, do not edit. | ||
// Source: squareup.protos.kotlin.swift_modules.SwiftEdgeCases in swift_edge_cases.proto | ||
import Foundation | ||
import Wire | ||
|
||
public struct SwiftEdgeCases { | ||
|
||
@ProtoDefaulted | ||
public var `return`: String? | ||
public var unknownFields: Foundation.Data = .init() | ||
|
||
public init(configure: (inout Self) -> Swift.Void = { _ in }) { | ||
configure(&self) | ||
} | ||
|
||
} | ||
|
||
#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER | ||
extension SwiftEdgeCases { | ||
|
||
@_disfavoredOverload | ||
@available(*, deprecated) | ||
public init(`return`: Swift.String? = nil) { | ||
self._return.wrappedValue = `return` | ||
} | ||
|
||
} | ||
#endif | ||
|
||
#if !WIRE_REMOVE_EQUATABLE | ||
extension SwiftEdgeCases : Equatable { | ||
} | ||
#endif | ||
|
||
#if !WIRE_REMOVE_HASHABLE | ||
extension SwiftEdgeCases : Hashable { | ||
} | ||
#endif | ||
|
||
#if swift(>=5.5) | ||
extension SwiftEdgeCases : Sendable { | ||
} | ||
#endif | ||
|
||
extension SwiftEdgeCases : ProtoDefaultedValue { | ||
|
||
public static var defaultedValue: SwiftEdgeCases { | ||
SwiftEdgeCases() | ||
} | ||
} | ||
|
||
extension SwiftEdgeCases : ProtoMessage { | ||
|
||
public static func protoMessageTypeURL() -> Swift.String { | ||
return "type.googleapis.com/squareup.protos.kotlin.swift_modules.SwiftEdgeCases" | ||
} | ||
|
||
} | ||
|
||
extension SwiftEdgeCases : Proto2Codable { | ||
|
||
public init(from protoReader: Wire.ProtoReader) throws { | ||
var `return`: 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) | ||
default: try protoReader.readUnknownField(tag: tag) | ||
} | ||
} | ||
self.unknownFields = try protoReader.endMessage(token: token) | ||
|
||
self._return.wrappedValue = `return` | ||
} | ||
|
||
public func encode(to protoWriter: Wire.ProtoWriter) throws { | ||
try protoWriter.encode(tag: 1, value: self.`return`) | ||
try protoWriter.writeUnknownFields(unknownFields) | ||
} | ||
|
||
} | ||
|
||
#if !WIRE_REMOVE_CODABLE | ||
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") | ||
} | ||
|
||
public func encode(to encoder: Swift.Encoder) throws { | ||
var container = encoder.container(keyedBy: Wire.StringLiteralCodingKeys.self) | ||
|
||
try container.encodeIfPresent(self.`return`, forKey: "return") | ||
} | ||
|
||
} | ||
#endif |
22 changes: 22 additions & 0 deletions
22
wire-tests/src/commonTest/proto/kotlin/swift_edge_cases.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2023 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
syntax = "proto2"; | ||
|
||
package squareup.protos.kotlin.swift_modules; | ||
|
||
message SwiftEdgeCases { | ||
optional string return = 1; | ||
} |