forked from protocolbuffers/protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPBUnknownFields.h
166 lines (142 loc) · 4.86 KB
/
GPBUnknownFields.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Protocol Buffers - Google's data interchange format
// Copyright 2024 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#import <Foundation/Foundation.h>
@class GPBMessage;
@class GPBUnknownField;
NS_ASSUME_NONNULL_BEGIN
/**
* A collection of unknown field numbers and their values.
*
* Note: `NSFastEnumeration` is supported to iterate over the `GPBUnknownFields`
* in order.
*
* Reminder: Any field number can occur multiple times. For example, if a .proto
* file were updated to a have a new (unpacked) repeated field, then each value
* would appear independently. Likewise, it is possible that a number appears
* multiple times with different data types, i.e. - unpacked vs. package repeated
* fields from concatenating binary blobs of data.
*/
__attribute__((objc_subclassing_restricted))
@interface GPBUnknownFields : NSObject<NSCopying, NSFastEnumeration>
/**
* Initializes a new instance with the data from the unknown fields from the given
* message.
*
* Note: The instance is not linked to the message, any change will not be
* reflected on the message the changes have to be pushed back to the message
* with `-[GPBMessage mergeUnknownFields:error:]`.
**/
- (instancetype)initFromMessage:(nonnull GPBMessage *)message;
/**
* Initializes a new empty instance.
**/
- (instancetype)init;
/**
* The number of fields in this set. A single field number can appear in
* multiple `GPBUnknownField` values as it might be a repeated field (it is
* also possible that they have different `type` values (for example package vs
* unpacked repeated fields).
*
* Note: `NSFastEnumeration` is supported to iterate over the fields in order.
**/
@property(nonatomic, readonly, assign) NSUInteger count;
/** If the set is empty or not. */
@property(nonatomic, readonly, assign) BOOL empty;
/**
* Removes all the fields current in the set.
**/
- (void)clear;
/**
* Fetches the subset of all the unknown fields that are for the given field
* number.
*
* @returns An `NSArray` of `GPBUnknownField`s or `nil` if there were none.
*/
- (nullable NSArray<GPBUnknownField *> *)fields:(int32_t)fieldNumber;
/**
* Add a new varint unknown field.
*
* @param fieldNumber The field number to use.
* @param value The value to add.
**/
- (void)addFieldNumber:(int32_t)fieldNumber varint:(uint64_t)value;
/**
* Add a new fixed32 unknown field.
*
* @param fieldNumber The field number to use.
* @param value The value to add.
**/
- (void)addFieldNumber:(int32_t)fieldNumber fixed32:(uint32_t)value;
/**
* Add a new fixed64 unknown field.
*
* @param fieldNumber The field number to use.
* @param value The value to add.
**/
- (void)addFieldNumber:(int32_t)fieldNumber fixed64:(uint64_t)value;
/**
* Add a new length delimited (length prefixed) unknown field.
*
* @param fieldNumber The field number to use.
* @param value The value to add.
**/
- (void)addFieldNumber:(int32_t)fieldNumber lengthDelimited:(nonnull NSData *)value;
/**
* Add a group (tag delimited) unknown field.
*
* @param fieldNumber The field number to use.
*
* @return A new `GPBUnknownFields` to set the field of the group too.
**/
- (nonnull GPBUnknownFields *)addGroupWithFieldNumber:(int32_t)fieldNumber;
@end
@interface GPBUnknownFields (AccessHelpers)
/**
* Fetches the first varint for the given field number.
*
* @param fieldNumber The field number to look for.
* @param outValue A pointer to receive the value if found
*
* @returns YES/NO on if there was a matching unknown field.
**/
- (BOOL)getFirst:(int32_t)fieldNumber varint:(nonnull uint64_t *)outValue;
/**
* Fetches the first fixed32 for the given field number.
*
* @param fieldNumber The field number to look for.
* @param outValue A pointer to receive the value if found
*
* @returns YES/NO on if there was a matching unknown field.
**/
- (BOOL)getFirst:(int32_t)fieldNumber fixed32:(nonnull uint32_t *)outValue;
/**
* Fetches the first fixed64 for the given field number.
*
* @param fieldNumber The field number to look for.
* @param outValue A pointer to receive the value if found
*
* @returns YES/NO on if there was a matching unknown field.
**/
- (BOOL)getFirst:(int32_t)fieldNumber fixed64:(nonnull uint64_t *)outValue;
/**
* Fetches the first length delimited (length prefixed) for the given field number.
*
* @param fieldNumber The field number to look for.
*
* @returns The first length delimited value for the given field number.
**/
- (nullable NSData *)firstLengthDelimited:(int32_t)fieldNumber;
/**
* Fetches the first group (tag delimited) field for the given field number.
*
* @param fieldNumber The field number to look for.
*
* @returns The first group for the given field number.
**/
- (nullable GPBUnknownFields *)firstGroup:(int32_t)fieldNumber;
@end
NS_ASSUME_NONNULL_END