1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2024 Google Inc. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 #import <Foundation/Foundation.h>
10 #import "GPBMessage.h"
11 #import "GPBUnknownField.h"
14 @
class GPBUnknownField
;
16 NS_ASSUME_NONNULL_BEGIN
19 * A collection of unknown field numbers and their values.
21 * Note: `NSFastEnumeration` is supported to iterate over the `GPBUnknownFields`
24 * Reminder: Any field number can occur multiple times. For example, if a .proto
25 * file were updated to a have a new (unpacked) repeated field, then each value
26 * would appear independently. Likewise, it is possible that a number appears
27 * multiple times with different data types, i.e. - unpacked vs. package repeated
28 * fields from concatenating binary blobs of data.
30 __attribute__((objc_subclassing_restricted
))
31 @interface GPBUnknownFields
: NSObject
<NSCopying
, NSFastEnumeration
>
34 * Initializes a new instance with the data from the unknown fields from the given
37 * Note: The instance is not linked to the message, any change will not be
38 * reflected on the message the changes have to be pushed back to the message
39 * with `-[GPBMessage mergeUnknownFields:extensionRegistry:error:]`.
41 - (instancetype
)initFromMessage
:(nonnull GPBMessage
*)message
;
44 * Initializes a new empty instance.
49 * The number of fields in this set. A single field number can appear in
50 * multiple `GPBUnknownField` values as it might be a repeated field (it is
51 * also possible that they have different `type` values (for example package vs
52 * unpacked repeated fields).
54 * Note: `NSFastEnumeration` is supported to iterate over the fields in order.
56 @
property(nonatomic
, readonly
, assign
) NSUInteger count
;
58 /** If the set is empty or not. */
59 @
property(nonatomic
, readonly
, assign
) BOOL empty
;
62 * Removes all the fields current in the set.
67 * Fetches the subset of all the unknown fields that are for the given field
70 * @returns An `NSArray` of `GPBUnknownField`s or `nil` if there were none.
72 - (nullable NSArray
<GPBUnknownField
*> *)fields
:(int32_t)fieldNumber
;
75 * Add a new varint unknown field.
77 * @param fieldNumber The field number to use.
78 * @param value The value to add.
80 - (void)addFieldNumber
:(int32_t)fieldNumber varint
:(uint64_t)value
;
83 * Add a new fixed32 unknown field.
85 * @param fieldNumber The field number to use.
86 * @param value The value to add.
88 - (void)addFieldNumber
:(int32_t)fieldNumber fixed32
:(uint32_t)value
;
91 * Add a new fixed64 unknown field.
93 * @param fieldNumber The field number to use.
94 * @param value The value to add.
96 - (void)addFieldNumber
:(int32_t)fieldNumber fixed64
:(uint64_t)value
;
99 * Add a new length delimited (length prefixed) unknown field.
101 * @param fieldNumber The field number to use.
102 * @param value The value to add.
104 - (void)addFieldNumber
:(int32_t)fieldNumber lengthDelimited
:(nonnull NSData
*)value
;
107 * Add a group (tag delimited) unknown field.
109 * @param fieldNumber The field number to use.
111 * @return A new `GPBUnknownFields` to set the field of the group too.
113 - (nonnull GPBUnknownFields
*)addGroupWithFieldNumber
:(int32_t)fieldNumber
;
116 * Add the copy of the given unknown field.
118 * This can be useful from processing one `GPBUnknownFields` to create another.
120 * NOTE: If the field being copied is an Group, this instance added is new and thus
121 * the `.group` of that result is also new, so if you intent is to modify the group
122 * it *must* be fetched out of the result.
124 * @param field The field to add.
126 * @return The autoreleased field that was added.
128 - (GPBUnknownField
*)addCopyOfField
:(nonnull GPBUnknownField
*)field
;
131 * Removes the given field from the set.
133 * It is a programming error to attempt to remove a field that is not in this collection.
135 * Reminder: it is not save to mutate the collection while also using fast enumeration on it.
137 * @param field The field to remove.
139 - (void)removeField
:(nonnull GPBUnknownField
*)field
;
142 * Removes all of the fields from the collection that have the given field number.
144 * If there are no fields with the given field number, this is a no-op.
146 * @param fieldNumber The field number to remove.
148 - (void)clearFieldNumber
:(int32_t)fieldNumber
;
152 @interface
GPBUnknownFields (AccessHelpers
)
155 * Fetches the first varint for the given field number.
157 * @param fieldNumber The field number to look for.
158 * @param outValue A pointer to receive the value if found
160 * @returns YES/NO on if there was a matching unknown field.
162 - (BOOL
)getFirst
:(int32_t)fieldNumber varint
:(nonnull
uint64_t *)outValue
;
165 * Fetches the first fixed32 for the given field number.
167 * @param fieldNumber The field number to look for.
168 * @param outValue A pointer to receive the value if found
170 * @returns YES/NO on if there was a matching unknown field.
172 - (BOOL
)getFirst
:(int32_t)fieldNumber fixed32
:(nonnull
uint32_t *)outValue
;
175 * Fetches the first fixed64 for the given field number.
177 * @param fieldNumber The field number to look for.
178 * @param outValue A pointer to receive the value if found
180 * @returns YES/NO on if there was a matching unknown field.
182 - (BOOL
)getFirst
:(int32_t)fieldNumber fixed64
:(nonnull
uint64_t *)outValue
;
185 * Fetches the first length delimited (length prefixed) for the given field number.
187 * @param fieldNumber The field number to look for.
189 * @returns The first length delimited value for the given field number.
191 - (nullable NSData
*)firstLengthDelimited
:(int32_t)fieldNumber
;
194 * Fetches the first group (tag delimited) field for the given field number.
196 * @param fieldNumber The field number to look for.
198 * @returns The first group for the given field number.
200 - (nullable GPBUnknownFields
*)firstGroup
:(int32_t)fieldNumber
;
204 NS_ASSUME_NONNULL_END