Skip to content

Commit e8cde94

Browse files
authored
Rework enums to use the same name mapping as message fields. (apple#320)
* Rename FieldNameMap to just _NameMap and use it with enums. Along with some other various cleanup. * Regenerate tests. * Update reference protos.
1 parent b46fc62 commit e8cde94

File tree

147 files changed

+7610
-20608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+7610
-20608
lines changed

Reference/conformance/conformance.pb.swift

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
6868
// - running as a sub-process may be more tricky in unusual environments like
6969
// iOS apps, where fork/stdin/stdout are not available.
7070

71-
enum Conformance_WireFormat: SwiftProtobuf.Enum {
71+
enum Conformance_WireFormat: SwiftProtobuf.Enum, SwiftProtobuf._ProtoNameProviding {
7272
typealias RawValue = Int
7373
case unspecified // = 0
7474
case protobuf // = 1
7575
case json // = 2
7676
case UNRECOGNIZED(Int)
7777

78+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
79+
0: .same(proto: "UNSPECIFIED"),
80+
1: .same(proto: "PROTOBUF"),
81+
2: .same(proto: "JSON"),
82+
]
83+
7884
init() {
7985
self = .unspecified
8086
}
@@ -88,43 +94,12 @@ enum Conformance_WireFormat: SwiftProtobuf.Enum {
8894
}
8995
}
9096

91-
init?(jsonName: String) {
92-
switch jsonName {
93-
case "UNSPECIFIED": self = .unspecified
94-
case "PROTOBUF": self = .protobuf
95-
case "JSON": self = .json
96-
default: return nil
97-
}
98-
}
99-
100-
init?(protoName: String) {
101-
switch protoName {
102-
case "UNSPECIFIED": self = .unspecified
103-
case "PROTOBUF": self = .protobuf
104-
case "JSON": self = .json
105-
default: return nil
106-
}
107-
}
108-
10997
var rawValue: Int {
110-
get {
111-
switch self {
112-
case .unspecified: return 0
113-
case .protobuf: return 1
114-
case .json: return 2
115-
case .UNRECOGNIZED(let i): return i
116-
}
117-
}
118-
}
119-
120-
var _protobuf_jsonName: String? {
121-
get {
122-
switch self {
123-
case .unspecified: return "UNSPECIFIED"
124-
case .protobuf: return "PROTOBUF"
125-
case .json: return "JSON"
126-
case .UNRECOGNIZED: return nil
127-
}
98+
switch self {
99+
case .unspecified: return 0
100+
case .protobuf: return 1
101+
case .json: return 2
102+
case .UNRECOGNIZED(let i): return i
128103
}
129104
}
130105

@@ -138,7 +113,7 @@ enum Conformance_WireFormat: SwiftProtobuf.Enum {
138113
struct Conformance_ConformanceRequest: SwiftProtobuf.Proto3Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
139114
static let protoMessageName: String = "ConformanceRequest"
140115
static let protoPackageName: String = "conformance"
141-
static let _protobuf_fieldNames: FieldNameMap = [
116+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
142117
1: .unique(proto: "protobuf_payload", json: "protobufPayload"),
143118
2: .unique(proto: "json_payload", json: "jsonPayload"),
144119
3: .unique(proto: "requested_output_format", json: "requestedOutputFormat"),
@@ -255,7 +230,7 @@ struct Conformance_ConformanceRequest: SwiftProtobuf.Proto3Message, SwiftProtobu
255230
struct Conformance_ConformanceResponse: SwiftProtobuf.Proto3Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
256231
static let protoMessageName: String = "ConformanceResponse"
257232
static let protoPackageName: String = "conformance"
258-
static let _protobuf_fieldNames: FieldNameMap = [
233+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
259234
1: .unique(proto: "parse_error", json: "parseError"),
260235
6: .unique(proto: "serialize_error", json: "serializeError"),
261236
2: .unique(proto: "runtime_error", json: "runtimeError"),

Reference/google/protobuf/any.pb.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
120120
struct Google_Protobuf_Any: SwiftProtobuf.Proto3Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
121121
static let protoMessageName: String = "Any"
122122
static let protoPackageName: String = "google.protobuf"
123-
static let _protobuf_fieldNames: FieldNameMap = [
123+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
124124
1: .unique(proto: "type_url", json: "typeUrl"),
125125
2: .same(proto: "value"),
126126
]

Reference/google/protobuf/any_test.pb.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
5252
struct ProtobufUnittest_TestAny: SwiftProtobuf.Proto3Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
5353
static let protoMessageName: String = "TestAny"
5454
static let protoPackageName: String = "protobuf_unittest"
55-
static let _protobuf_fieldNames: FieldNameMap = [
55+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
5656
1: .unique(proto: "int32_value", json: "int32Value"),
5757
2: .unique(proto: "any_value", json: "anyValue"),
5858
3: .unique(proto: "repeated_any_value", json: "repeatedAnyValue"),

Reference/google/protobuf/api.pb.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
5252
struct Google_Protobuf_Api: SwiftProtobuf.Proto3Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
5353
static let protoMessageName: String = "Api"
5454
static let protoPackageName: String = "google.protobuf"
55-
static let _protobuf_fieldNames: FieldNameMap = [
55+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
5656
1: .same(proto: "name"),
5757
2: .same(proto: "methods"),
5858
3: .same(proto: "options"),
@@ -233,7 +233,7 @@ struct Google_Protobuf_Api: SwiftProtobuf.Proto3Message, SwiftProtobuf._MessageI
233233
struct Google_Protobuf_Method: SwiftProtobuf.Proto3Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
234234
static let protoMessageName: String = "Method"
235235
static let protoPackageName: String = "google.protobuf"
236-
static let _protobuf_fieldNames: FieldNameMap = [
236+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
237237
1: .same(proto: "name"),
238238
2: .unique(proto: "request_type_url", json: "requestTypeUrl"),
239239
3: .unique(proto: "request_streaming", json: "requestStreaming"),
@@ -401,7 +401,7 @@ struct Google_Protobuf_Method: SwiftProtobuf.Proto3Message, SwiftProtobuf._Messa
401401
struct Google_Protobuf_Mixin: SwiftProtobuf.Proto3Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
402402
static let protoMessageName: String = "Mixin"
403403
static let protoPackageName: String = "google.protobuf"
404-
static let _protobuf_fieldNames: FieldNameMap = [
404+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
405405
1: .same(proto: "name"),
406406
2: .same(proto: "root"),
407407
]

Reference/google/protobuf/compiler/plugin.pb.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
6969
struct Google_Protobuf_Compiler_Version: SwiftProtobuf.Proto2Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
7070
static let protoMessageName: String = "Version"
7171
static let protoPackageName: String = "google.protobuf.compiler"
72-
static let _protobuf_fieldNames: FieldNameMap = [
72+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
7373
1: .same(proto: "major"),
7474
2: .same(proto: "minor"),
7575
3: .same(proto: "patch"),
@@ -176,7 +176,7 @@ struct Google_Protobuf_Compiler_Version: SwiftProtobuf.Proto2Message, SwiftProto
176176
struct Google_Protobuf_Compiler_CodeGeneratorRequest: SwiftProtobuf.Proto2Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
177177
static let protoMessageName: String = "CodeGeneratorRequest"
178178
static let protoPackageName: String = "google.protobuf.compiler"
179-
static let _protobuf_fieldNames: FieldNameMap = [
179+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
180180
1: .unique(proto: "file_to_generate", json: "fileToGenerate"),
181181
2: .same(proto: "parameter"),
182182
15: .unique(proto: "proto_file", json: "protoFile"),
@@ -323,7 +323,7 @@ struct Google_Protobuf_Compiler_CodeGeneratorRequest: SwiftProtobuf.Proto2Messag
323323
struct Google_Protobuf_Compiler_CodeGeneratorResponse: SwiftProtobuf.Proto2Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
324324
static let protoMessageName: String = "CodeGeneratorResponse"
325325
static let protoPackageName: String = "google.protobuf.compiler"
326-
static let _protobuf_fieldNames: FieldNameMap = [
326+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
327327
1: .same(proto: "error"),
328328
15: .same(proto: "file"),
329329
]
@@ -356,7 +356,7 @@ struct Google_Protobuf_Compiler_CodeGeneratorResponse: SwiftProtobuf.Proto2Messa
356356
struct File: SwiftProtobuf.Proto2Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
357357
static let protoMessageName: String = "File"
358358
static let protoPackageName: String = "google.protobuf.compiler"
359-
static let _protobuf_fieldNames: FieldNameMap = [
359+
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
360360
1: .same(proto: "name"),
361361
2: .unique(proto: "insertion_point", json: "insertionPoint"),
362362
15: .same(proto: "content"),

0 commit comments

Comments
 (0)