Skip to content

Commit 47f633e

Browse files
thomasvlcopybara-github
authored andcommitted
[ObjC] Introduce the new GPBUnknownFields type.
`GPBUnknownFields` will be the eventually replacement for `GPBUnknownFieldSet`. This introduces the type and the changes to `GPBUnknownField`. The new api will preserve the wire ordering of unknown fields. This is now checked in conformance tests. While this adds the type changes and tests them, it does not yet wire the changes in to the rest of the Runtime, so the conformance tests still done pass. `GPBUnknownFieldSet` also hasn't been deprecated yet, that will come in later with the wiring in to the runtime. PiperOrigin-RevId: 648361455
1 parent a4f9ddd commit 47f633e

File tree

13 files changed

+1374
-129
lines changed

13 files changed

+1374
-129
lines changed

objectivec/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ objc_library(
8484
"GPBRootObject.h",
8585
"GPBRuntimeTypes.h",
8686
"GPBUnknownField.h",
87+
"GPBUnknownFields.h",
8788
"GPBUnknownFieldSet.h",
8889
"GPBUtilities.h",
8990
"GPBWellKnownTypes.h",
@@ -138,6 +139,7 @@ objc_library(
138139
"GPBType.pbobjc.m",
139140
"GPBUnknownField.m",
140141
"GPBUnknownFieldSet.m",
142+
"GPBUnknownFields.m",
141143
"GPBUtilities.m",
142144
"GPBWellKnownTypes.m",
143145
"GPBWireFormat.m",

objectivec/GPBProtocolBuffers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#import "GPBRootObject.h"
2020
#import "GPBUnknownField.h"
2121
#import "GPBUnknownFieldSet.h"
22+
#import "GPBUnknownFields.h"
2223
#import "GPBUtilities.h"
2324
#import "GPBWellKnownTypes.h"
2425
#import "GPBWireFormat.h"

objectivec/GPBProtocolBuffers.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#import "GPBRootObject.m"
2727
#import "GPBUnknownField.m"
2828
#import "GPBUnknownFieldSet.m"
29+
#import "GPBUnknownFields.m"
2930
#import "GPBUtilities.m"
3031
#import "GPBWellKnownTypes.m"
3132
#import "GPBWireFormat.m"

objectivec/GPBUnknownField.h

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,25 @@
1111
@class GPBUInt32Array;
1212
@class GPBUInt64Array;
1313
@class GPBUnknownFieldSet;
14+
@class GPBUnknownFields;
1415

1516
NS_ASSUME_NONNULL_BEGIN
17+
18+
typedef NS_ENUM(uint8_t, GPBUnknownFieldType) {
19+
GPBUnknownFieldTypeVarint,
20+
GPBUnknownFieldTypeFixed32,
21+
GPBUnknownFieldTypeFixed64,
22+
GPBUnknownFieldTypeLengthDelimited, // Length prefixed
23+
GPBUnknownFieldTypeGroup, // Tag delimited
24+
25+
/**
26+
* This type is only used with fields from `GPBUnknownFieldsSet`. Some methods
27+
* only work with instances with this type and other apis require the other
28+
* type(s). It is a programming error to use the wrong methods.
29+
**/
30+
GPBUnknownFieldTypeLegacy,
31+
};
32+
1633
/**
1734
* Store an unknown field. These are used in conjunction with
1835
* GPBUnknownFieldSet.
@@ -26,48 +43,127 @@ __attribute__((objc_subclassing_restricted))
2643
/** The field number the data is stored under. */
2744
@property(nonatomic, readonly, assign) int32_t number;
2845

29-
/** An array of varint values for this field. */
46+
/** The type of the field. */
47+
@property(nonatomic, readonly, assign) GPBUnknownFieldType type;
48+
49+
/**
50+
* Fetch the varint value.
51+
*
52+
* It is a programming error to call this when the `type` is not a varint.
53+
*/
54+
@property(nonatomic, readonly, assign) uint64_t varint;
55+
56+
/**
57+
* Fetch the fixed32 value.
58+
*
59+
* It is a programming error to call this when the `type` is not a fixed32.
60+
*/
61+
@property(nonatomic, readonly, assign) uint32_t fixed32;
62+
63+
/**
64+
* Fetch the fixed64 value.
65+
*
66+
* It is a programming error to call this when the `type` is not a fixed64.
67+
*/
68+
@property(nonatomic, readonly, assign) uint64_t fixed64;
69+
70+
/**
71+
* Fetch the length delimited (length prefixed) value.
72+
*
73+
* It is a programming error to call this when the `type` is not a length
74+
* delimited.
75+
*/
76+
@property(nonatomic, readonly, strong, nonnull) NSData *lengthDelimited;
77+
78+
/**
79+
* Fetch the group (tag delimited) value.
80+
*
81+
* It is a programming error to call this when the `type` is not a group.
82+
*/
83+
@property(nonatomic, readonly, strong, nonnull) GPBUnknownFields *group;
84+
85+
/**
86+
* An array of varint values for this field.
87+
*
88+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
89+
* to use with any other type.
90+
*/
3091
@property(nonatomic, readonly, strong) GPBUInt64Array *varintList;
3192

32-
/** An array of fixed32 values for this field. */
93+
/**
94+
* An array of fixed32 values for this field.
95+
*
96+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
97+
* to use with any other type.
98+
*/
3399
@property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List;
34100

35-
/** An array of fixed64 values for this field. */
101+
/**
102+
* An array of fixed64 values for this field.
103+
*
104+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
105+
* to use with any other type.
106+
*/
36107
@property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List;
37108

38-
/** An array of data values for this field. */
109+
/**
110+
* An array of data values for this field.
111+
*
112+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
113+
* to use with any other type.
114+
*/
39115
@property(nonatomic, readonly, strong) NSArray<NSData *> *lengthDelimitedList;
40116

41-
/** An array of groups of values for this field. */
117+
/**
118+
* An array of groups of values for this field.
119+
*
120+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
121+
* to use with any other type.
122+
*/
42123
@property(nonatomic, readonly, strong) NSArray<GPBUnknownFieldSet *> *groupList;
43124

44125
/**
45126
* Add a value to the varintList.
46127
*
128+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
129+
* to use with any other type.
130+
*
47131
* @param value The value to add.
48132
**/
49133
- (void)addVarint:(uint64_t)value;
50134
/**
51135
* Add a value to the fixed32List.
52136
*
137+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
138+
* to use with any other type.
139+
*
53140
* @param value The value to add.
54141
**/
55142
- (void)addFixed32:(uint32_t)value;
56143
/**
57144
* Add a value to the fixed64List.
58145
*
146+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
147+
* to use with any other type.
148+
*
59149
* @param value The value to add.
60150
**/
61151
- (void)addFixed64:(uint64_t)value;
62152
/**
63153
* Add a value to the lengthDelimitedList.
64154
*
155+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
156+
* to use with any other type.
157+
*
65158
* @param value The value to add.
66159
**/
67160
- (void)addLengthDelimited:(NSData *)value;
68161
/**
69162
* Add a value to the groupList.
70163
*
164+
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
165+
* to use with any other type.
166+
*
71167
* @param value The value to add.
72168
**/
73169
- (void)addGroup:(GPBUnknownFieldSet *)value;

0 commit comments

Comments
 (0)