Skip to content

Commit 60153e3

Browse files
authored
Support TextFormat skipping reserved field names and numbers.
The spec calls for this, so just building out the matching support. - Update `_NameMap` to track reserved numbers and names and check if a value is reserved. - Update `TextFormatScanner` to skip reserved numbers/names. - Update the generator to capture reserved field names/numbers. - Sort/merge the reserved field ranges. This won't really make an performance difference, but by merging them the generate data could end up being smaller. - Factor the code out of the extension range code so it can be used also for the reserved fields. - Regenerate to pick up the new data. - Also clear `text_format_failure_list_swift.txt` as the tests now pass with the additional data. - Update the generated_swift_names_* files. - Add a test to ensure reserved fields don't break parsing.
1 parent e41d3f0 commit 60153e3

File tree

46 files changed

+13295
-12751
lines changed

Some content is hidden

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

46 files changed

+13295
-12751
lines changed

Protos/SwiftProtobufTests/generated_swift_names_enum_cases.proto

Lines changed: 519 additions & 518 deletions
Large diffs are not rendered by default.

Protos/SwiftProtobufTests/generated_swift_names_enums.proto

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ message GeneratedSwiftReservedEnums {
1212
enum alwaysPrintEnumsAsInts { NONE_alwaysPrintEnumsAsInts = 0; }
1313
enum alwaysPrintInt64sAsNumbers { NONE_alwaysPrintInt64sAsNumbers = 0; }
1414
enum annotation { NONE_annotation = 0; }
15-
enum any { NONE_any = 0; }
15+
enum Any { NONE_Any = 0; }
1616
enum AnyExtensionField { NONE_AnyExtensionField = 0; }
1717
enum AnyMessageExtension { NONE_AnyMessageExtension = 0; }
1818
enum AnyMessageStorage { NONE_AnyMessageStorage = 0; }
@@ -193,7 +193,7 @@ message GeneratedSwiftReservedEnums {
193193
enum customCodable { NONE_customCodable = 0; }
194194
enum CustomDebugStringConvertible { NONE_CustomDebugStringConvertible = 0; }
195195
enum CustomStringConvertible { NONE_CustomStringConvertible = 0; }
196-
enum d { NONE_d = 0; }
196+
enum D { NONE_D = 0; }
197197
enum Data { NONE_Data = 0; }
198198
enum dataResult { NONE_dataResult = 0; }
199199
enum date { NONE_date = 0; }
@@ -209,7 +209,7 @@ message GeneratedSwiftReservedEnums {
209209
enum decodeJSON { NONE_decodeJSON = 0; }
210210
enum decodeMapField { NONE_decodeMapField = 0; }
211211
enum decodeMessage { NONE_decodeMessage = 0; }
212-
enum decoder { NONE_decoder = 0; }
212+
enum Decoder { NONE_Decoder = 0; }
213213
enum decodeRepeated { NONE_decodeRepeated = 0; }
214214
enum decodeRepeatedBoolField { NONE_decodeRepeatedBoolField = 0; }
215215
enum decodeRepeatedBytesField { NONE_decodeRepeatedBytesField = 0; }
@@ -271,7 +271,7 @@ message GeneratedSwiftReservedEnums {
271271
enum discardUnknownFields { NONE_discardUnknownFields = 0; }
272272
enum Double { NONE_Double = 0; }
273273
enum doubleValue { NONE_doubleValue = 0; }
274-
enum duration { NONE_duration = 0; }
274+
enum Duration { NONE_Duration = 0; }
275275
enum E { NONE_E = 0; }
276276
enum edition { NONE_edition = 0; }
277277
enum EditionDefault { NONE_EditionDefault = 0; }
@@ -384,7 +384,6 @@ message GeneratedSwiftReservedEnums {
384384
enum GeneratedCodeInfo { NONE_GeneratedCodeInfo = 0; }
385385
enum get { NONE_get = 0; }
386386
enum getExtensionValue { NONE_getExtensionValue = 0; }
387-
enum googleapis { NONE_googleapis = 0; }
388387
enum Google_Protobuf_Any { NONE_Google_Protobuf_Any = 0; }
389388
enum Google_Protobuf_Api { NONE_Google_Protobuf_Api = 0; }
390389
enum Google_Protobuf_BoolValue { NONE_Google_Protobuf_BoolValue = 0; }
@@ -438,6 +437,7 @@ message GeneratedSwiftReservedEnums {
438437
enum Google_Protobuf_UInt64Value { NONE_Google_Protobuf_UInt64Value = 0; }
439438
enum Google_Protobuf_UninterpretedOption { NONE_Google_Protobuf_UninterpretedOption = 0; }
440439
enum Google_Protobuf_Value { NONE_Google_Protobuf_Value = 0; }
440+
enum googleapis { NONE_googleapis = 0; }
441441
enum goPackage { NONE_goPackage = 0; }
442442
enum gotData { NONE_gotData = 0; }
443443
enum group { NONE_group = 0; }
@@ -577,6 +577,7 @@ message GeneratedSwiftReservedEnums {
577577
enum isInitialized { NONE_isInitialized = 0; }
578578
enum isNegative { NONE_isNegative = 0; }
579579
enum isPathValid { NONE_isPathValid = 0; }
580+
enum isReserved { NONE_isReserved = 0; }
580581
enum isValid { NONE_isValid = 0; }
581582
enum itemTagsEncodedSize { NONE_itemTagsEncodedSize = 0; }
582583
enum iterator { NONE_iterator = 0; }
@@ -695,12 +696,12 @@ message GeneratedSwiftReservedEnums {
695696
enum numberValue { NONE_numberValue = 0; }
696697
enum objcClassPrefix { NONE_objcClassPrefix = 0; }
697698
enum of { NONE_of = 0; }
699+
enum OneOf_Kind { NONE_OneOf_Kind = 0; }
698700
enum oneofDecl { NONE_oneofDecl = 0; }
699701
enum OneofDescriptorProto { NONE_OneofDescriptorProto = 0; }
700702
enum oneofIndex { NONE_oneofIndex = 0; }
701703
enum OneofOptions { NONE_OneofOptions = 0; }
702704
enum oneofs { NONE_oneofs = 0; }
703-
enum OneOf_Kind { NONE_OneOf_Kind = 0; }
704705
enum optimizeFor { NONE_optimizeFor = 0; }
705706
enum OptimizeMode { NONE_OptimizeMode = 0; }
706707
enum Option { NONE_Option = 0; }
@@ -746,8 +747,14 @@ message GeneratedSwiftReservedEnums {
746747
enum proto2 { NONE_proto2 = 0; }
747748
enum proto3DefaultValue { NONE_proto3DefaultValue = 0; }
748749
enum proto3Optional { NONE_proto3Optional = 0; }
749-
enum ProtobufAPIVersionCheck { NONE_ProtobufAPIVersionCheck = 0; }
750+
enum protobuf_extensionFieldValues { NONE_protobuf_extensionFieldValues = 0; }
751+
enum protobuf_fieldNumber { NONE_protobuf_fieldNumber = 0; }
752+
enum protobuf_generated_isEqualTo { NONE_protobuf_generated_isEqualTo = 0; }
753+
enum protobuf_nameMap { NONE_protobuf_nameMap = 0; }
754+
enum protobuf_newField { NONE_protobuf_newField = 0; }
755+
enum protobuf_package { NONE_protobuf_package = 0; }
750756
enum ProtobufAPIVersion_2 { NONE_ProtobufAPIVersion_2 = 0; }
757+
enum ProtobufAPIVersionCheck { NONE_ProtobufAPIVersionCheck = 0; }
751758
enum ProtobufBool { NONE_ProtobufBool = 0; }
752759
enum ProtobufBytes { NONE_ProtobufBytes = 0; }
753760
enum ProtobufDouble { NONE_ProtobufDouble = 0; }
@@ -767,12 +774,6 @@ message GeneratedSwiftReservedEnums {
767774
enum ProtobufString { NONE_ProtobufString = 0; }
768775
enum ProtobufUInt32 { NONE_ProtobufUInt32 = 0; }
769776
enum ProtobufUInt64 { NONE_ProtobufUInt64 = 0; }
770-
enum protobuf_extensionFieldValues { NONE_protobuf_extensionFieldValues = 0; }
771-
enum protobuf_fieldNumber { NONE_protobuf_fieldNumber = 0; }
772-
enum protobuf_generated_isEqualTo { NONE_protobuf_generated_isEqualTo = 0; }
773-
enum protobuf_nameMap { NONE_protobuf_nameMap = 0; }
774-
enum protobuf_newField { NONE_protobuf_newField = 0; }
775-
enum protobuf_package { NONE_protobuf_package = 0; }
776777
enum protocol { NONE_protocol = 0; }
777778
enum protoFieldName { NONE_protoFieldName = 0; }
778779
enum protoMessageName { NONE_protoMessageName = 0; }
@@ -953,22 +954,22 @@ message GeneratedSwiftReservedEnums {
953954
enum utf8ToDouble { NONE_utf8ToDouble = 0; }
954955
enum utf8Validation { NONE_utf8Validation = 0; }
955956
enum UTF8View { NONE_UTF8View = 0; }
956-
enum v { NONE_v = 0; }
957+
enum V { NONE_V = 0; }
957958
enum value { NONE_value = 0; }
958959
enum valueField { NONE_valueField = 0; }
959960
enum values { NONE_values = 0; }
960961
enum ValueType { NONE_ValueType = 0; }
961962
enum var { NONE_var = 0; }
962963
enum verification { NONE_verification = 0; }
963964
enum VerificationState { NONE_VerificationState = 0; }
964-
enum Version { NONE_Version = 0; }
965+
enum version { NONE_version = 0; }
965966
enum versionString { NONE_versionString = 0; }
966967
enum visibility { NONE_visibility = 0; }
967968
enum VisibilityFeature { NONE_VisibilityFeature = 0; }
968969
enum visitExtensionFields { NONE_visitExtensionFields = 0; }
969970
enum visitExtensionFieldsAsMessageSet { NONE_visitExtensionFieldsAsMessageSet = 0; }
970971
enum visitMapField { NONE_visitMapField = 0; }
971-
enum visitor { NONE_visitor = 0; }
972+
enum Visitor { NONE_Visitor = 0; }
972973
enum visitPacked { NONE_visitPacked = 0; }
973974
enum visitPackedBoolField { NONE_visitPackedBoolField = 0; }
974975
enum visitPackedDoubleField { NONE_visitPackedDoubleField = 0; }

0 commit comments

Comments
 (0)