Merge pull request #17787 from thomasvl/patch_objc_to_28

CherryPick the lastest work for Objective-C over the the 28 branch
pull/17806/head
zhangskz 4 months ago committed by GitHub
commit 2d5c7293de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      objectivec/GPBCodedInputStream.m
  2. 3
      objectivec/GPBCodedInputStream_PackagePrivate.h
  3. 20
      objectivec/GPBCodedOutputStream.h
  4. 23
      objectivec/GPBCodedOutputStream.m
  5. 6
      objectivec/GPBCodedOutputStream_PackagePrivate.h
  6. 15
      objectivec/GPBMessage.h
  7. 24
      objectivec/GPBMessage.m
  8. 41
      objectivec/GPBUnknownField.h
  9. 15
      objectivec/GPBUnknownField.m
  10. 1
      objectivec/GPBUnknownFieldSet.h
  11. 9
      objectivec/GPBUnknownFieldSet.m
  12. 3
      objectivec/GPBUnknownField_PackagePrivate.h
  13. 3
      objectivec/Tests/GPBCodedInputStreamTests.m
  14. 11
      objectivec/Tests/GPBMessageTests+Serialization.m
  15. 26
      objectivec/Tests/GPBMessageTests.m
  16. 5
      objectivec/Tests/GPBUnknownFieldSetTest.m
  17. 51
      objectivec/Tests/GPBUnknownFieldsTest.m
  18. 13
      objectivec/Tests/GPBUtilitiesTests.m
  19. 9
      objectivec/Tests/GPBWireFormatTests.m

@ -494,6 +494,8 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t
--state_.recursionDepth; --state_.recursionDepth;
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message { - (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message {
CheckRecursionLimit(&state_); CheckRecursionLimit(&state_);
++state_.recursionDepth; ++state_.recursionDepth;
@ -502,6 +504,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t
GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
--state_.recursionDepth; --state_.recursionDepth;
} }
#pragma clang diagnostic pop
- (void)readMessage:(GPBMessage *)message - (void)readMessage:(GPBMessage *)message
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry { extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {

@ -42,7 +42,10 @@ typedef struct GPBCodedInputStreamState {
// Reads a group field value from the stream and merges it into the given // Reads a group field value from the stream and merges it into the given
// UnknownFieldSet. // UnknownFieldSet.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message; - (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message;
#pragma clang diagnostic pop
// Reads a map entry. // Reads a map entry.
- (void)readMapEntry:(id)mapDictionary - (void)readMapEntry:(id)mapDictionary

@ -589,6 +589,10 @@ __attribute__((objc_subclassing_restricted))
- (void)writeGroupNoTag:(int32_t)fieldNumber - (void)writeGroupNoTag:(int32_t)fieldNumber
value:(GPBMessage *)value; value:(GPBMessage *)value;
//%PDDM-EXPAND-END _WRITE_DECLS()
// clang-format on
/** /**
* Write a GPBUnknownFieldSet for the given field number. * Write a GPBUnknownFieldSet for the given field number.
* *
@ -596,7 +600,9 @@ __attribute__((objc_subclassing_restricted))
* @param value The value to write out. * @param value The value to write out.
**/ **/
- (void)writeUnknownGroup:(int32_t)fieldNumber - (void)writeUnknownGroup:(int32_t)fieldNumber
value:(GPBUnknownFieldSet *)value; value:(GPBUnknownFieldSet *)value
__attribute__((deprecated("GPBUnknownFieldSet is going away.")));
/** /**
* Write an array of GPBUnknownFieldSet for the given field number. * Write an array of GPBUnknownFieldSet for the given field number.
* *
@ -604,7 +610,9 @@ __attribute__((objc_subclassing_restricted))
* @param values The values to write out. * @param values The values to write out.
**/ **/
- (void)writeUnknownGroupArray:(int32_t)fieldNumber - (void)writeUnknownGroupArray:(int32_t)fieldNumber
values:(NSArray<GPBUnknownFieldSet*> *)values; values:(NSArray<GPBUnknownFieldSet *> *)values
__attribute__((deprecated("GPBUnknownFieldSet is going away.")));
/** /**
* Write a GPBUnknownFieldSet without any tag (but does write the endGroup tag). * Write a GPBUnknownFieldSet without any tag (but does write the endGroup tag).
* *
@ -612,11 +620,8 @@ __attribute__((objc_subclassing_restricted))
* @param value The value to write out. * @param value The value to write out.
**/ **/
- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber - (void)writeUnknownGroupNoTag:(int32_t)fieldNumber
value:(GPBUnknownFieldSet *)value; value:(GPBUnknownFieldSet *)value
__attribute__((deprecated("GPBUnknownFieldSet is going away.")));
//%PDDM-EXPAND-END _WRITE_DECLS()
// clang-format on
/** /**
Write a MessageSet extension field to the stream. For historical reasons, Write a MessageSet extension field to the stream. For historical reasons,
@ -741,6 +746,5 @@ NS_ASSUME_NONNULL_END
//%_WRITE_UNPACKABLE_DECLS(Message, GPBMessage) //%_WRITE_UNPACKABLE_DECLS(Message, GPBMessage)
//%_WRITE_UNPACKABLE_DECLS(Bytes, NSData) //%_WRITE_UNPACKABLE_DECLS(Bytes, NSData)
//%_WRITE_GROUP_DECLS(Group, GPBMessage) //%_WRITE_GROUP_DECLS(Group, GPBMessage)
//%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet)
// clang-format on // clang-format on

@ -352,6 +352,9 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value
[self writeGroupNoTag:fieldNumber value:value]; [self writeGroupNoTag:fieldNumber value:value];
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber value:(const GPBUnknownFieldSet *)value { - (void)writeUnknownGroupNoTag:(int32_t)fieldNumber value:(const GPBUnknownFieldSet *)value {
[value writeToCodedOutputStream:self]; [value writeToCodedOutputStream:self];
GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup); GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup);
@ -362,6 +365,8 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value
[self writeUnknownGroupNoTag:fieldNumber value:value]; [self writeUnknownGroupNoTag:fieldNumber value:value];
} }
#pragma clang diagnostic pop
- (void)writeMessageNoTag:(GPBMessage *)value { - (void)writeMessageNoTag:(GPBMessage *)value {
GPBWriteRawVarint32(&state_, (int32_t)[value serializedSize]); GPBWriteRawVarint32(&state_, (int32_t)[value serializedSize]);
[value writeToCodedOutputStream:self]; [value writeToCodedOutputStream:self];
@ -838,8 +843,12 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value
} }
} }
//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(UnknownGroup, GPBUnknownFieldSet) //%PDDM-EXPAND-END (19 expansions)
// This block of code is generated, do not edit it directly.
// clang-format on
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values { - (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values {
for (GPBUnknownFieldSet *value in values) { for (GPBUnknownFieldSet *value in values) {
@ -847,9 +856,7 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value
} }
} }
//%PDDM-EXPAND-END (19 expansions) #pragma clang diagnostic pop
// clang-format on
- (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value { - (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value {
GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatStartGroup); GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatStartGroup);
@ -982,7 +989,10 @@ size_t GPBComputeStringSizeNoTag(NSString *value) {
size_t GPBComputeGroupSizeNoTag(GPBMessage *value) { return [value serializedSize]; } size_t GPBComputeGroupSizeNoTag(GPBMessage *value) { return [value serializedSize]; }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) { return value.serializedSize; } size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) { return value.serializedSize; }
#pragma clang diagnostic pop
size_t GPBComputeMessageSizeNoTag(GPBMessage *value) { size_t GPBComputeMessageSizeNoTag(GPBMessage *value) {
size_t size = [value serializedSize]; size_t size = [value serializedSize];
@ -1050,9 +1060,12 @@ size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) {
return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeGroupSizeNoTag(value); return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeGroupSizeNoTag(value);
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value) { size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value) {
return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeUnknownGroupSizeNoTag(value); return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeUnknownGroupSizeNoTag(value);
} }
#pragma clang diagnostic pop
size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) { size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) {
return GPBComputeTagSize(fieldNumber) + GPBComputeMessageSizeNoTag(value); return GPBComputeTagSize(fieldNumber) + GPBComputeMessageSizeNoTag(value);

@ -21,8 +21,11 @@ size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) __attribute__(
size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) __attribute__((const)); size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) __attribute__((const));
size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) __attribute__((const)); size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) __attribute__((const));
size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const)); size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const));
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value) size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value)
__attribute__((const)); __attribute__((const));
#pragma clang diagnostic pop
size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const)); size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const));
size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) __attribute__((const)); size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) __attribute__((const));
size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) __attribute__((const)); size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) __attribute__((const));
@ -43,7 +46,10 @@ size_t GPBComputeFixed32SizeNoTag(uint32_t value) __attribute__((const));
size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const)); size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const));
size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const)); size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const));
size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const)); size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const));
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) __attribute__((const)); size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) __attribute__((const));
#pragma clang diagnostic pop
size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const)); size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const));
size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const)); size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const));
size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const)); size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const));

@ -55,8 +55,8 @@ CF_EXTERN_C_END
* exist in two places, you don't want a sub message to be a property * exist in two places, you don't want a sub message to be a property
* property of two other messages. * property of two other messages.
* *
* @note While the class support NSSecureCoding, if the message has any * @note While the class supports NSSecureCoding, if the message has any
* extensions, they will end up reloaded in @c unknownFields as there is * extensions, they will end up reloaded in the unknown fields as there is
* no way for the @c NSCoding plumbing to pass through a * no way for the @c NSCoding plumbing to pass through a
* @c GPBExtensionRegistry. To support extensions, instead of passing the * @c GPBExtensionRegistry. To support extensions, instead of passing the
* calls off to the Message, simple store the result of @c data, and then * calls off to the Message, simple store the result of @c data, and then
@ -73,7 +73,9 @@ CF_EXTERN_C_END
/** /**
* The set of unknown fields for this message. * The set of unknown fields for this message.
**/ **/
@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields; @property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields __attribute__((
deprecated("Use GPBUnknownFields and the -initFromMessage: initializer and "
"mergeUnknownFields:extensionRegistry:error: to add the data back to a message.")));
/** /**
* Whether the message, along with all submessages, have the required fields * Whether the message, along with all submessages, have the required fields
@ -510,10 +512,11 @@ CF_EXTERN_C_END
* If the intent is to *replace* the message's unknown fields, call `-clearUnknownFields` first. * If the intent is to *replace* the message's unknown fields, call `-clearUnknownFields` first.
* *
* Since the data from the GPBUnknownFields will always be well formed, this call will almost never * Since the data from the GPBUnknownFields will always be well formed, this call will almost never
* fail. What could cause it to fail is if the GPBUnknownFields contains a field values it is * fail. What could cause it to fail is if the GPBUnknownFields contains a field value that is
* and error for the message's schema - i.e.: if it contains a length delimited field where the * an error for the message's schema - i.e.: if it contains a length delimited field where the
* field number for the message is defined to be a _string_ field, however the length delimited * field number for the message is defined to be a _string_ field, however the length delimited
* data provide is not a valid UTF8 string. * data provide is not a valid UTF8 string, or if the field is a _packed_ number field, but the
* data provided is not a valid for that field.
* *
* @param unknownFields The unknown fields to merge the data from. * @param unknownFields The unknown fields to merge the data from.
* @param extensionRegistry The extension registry to use to look up extensions, can be `nil`. * @param extensionRegistry The extension registry to use to look up extensions, can be `nil`.

@ -79,7 +79,10 @@ NSString *const GPBMessageExceptionMessageTooLarge =
// be protected with an @synchronized(self) block (that way the code also doesn't have to // be protected with an @synchronized(self) block (that way the code also doesn't have to
// worry about throws). // worry about throws).
NSMutableData *unknownFieldData_; NSMutableData *unknownFieldData_;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknownFields_; GPBUnknownFieldSet *unknownFields_;
#pragma clang diagnostic pop
NSMutableDictionary *extensionMap_; NSMutableDictionary *extensionMap_;
// Readonly access to autocreatedExtensionMap_ is protected via readOnlyLock_. // Readonly access to autocreatedExtensionMap_ is protected via readOnlyLock_.
@ -1106,6 +1109,8 @@ void GPBClearMessageAutocreator(GPBMessage *self) {
self->autocreatorExtension_ = nil; self->autocreatorExtension_ = nil;
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPB_NOINLINE GPB_NOINLINE
static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data, static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
GPBUnknownFieldSet *targetSet) { GPBUnknownFieldSet *targetSet) {
@ -1151,6 +1156,7 @@ static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
[decodeInto release]; [decodeInto release];
} }
} }
#pragma clang diagnostic pop
@implementation GPBMessage @implementation GPBMessage
@ -1481,7 +1487,14 @@ static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
} }
- (void)clearUnknownFields { - (void)clearUnknownFields {
self.unknownFields = nil; [unknownFieldData_ release];
unknownFieldData_ = nil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[unknownFields_ release];
unknownFields_ = nil;
#pragma clang diagnostic pop
GPBBecomeVisibleToAutocreator(self);
} }
- (BOOL)mergeUnknownFields:(GPBUnknownFields *)unknownFields - (BOOL)mergeUnknownFields:(GPBUnknownFields *)unknownFields
@ -3149,6 +3162,8 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
// need to guard against is concurrent r/o access, so we can grab the values (and retain them) // need to guard against is concurrent r/o access, so we can grab the values (and retain them)
// so we have a version to compare against safely incase the second access causes the transform // so we have a version to compare against safely incase the second access causes the transform
// between internal states. // between internal states.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *selfUnknownFields; GPBUnknownFieldSet *selfUnknownFields;
NSData *selfUnknownFieldData; NSData *selfUnknownFieldData;
@synchronized(self) { @synchronized(self) {
@ -3161,6 +3176,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
otherUnknownFields = [otherMsg->unknownFields_ retain]; otherUnknownFields = [otherMsg->unknownFields_ retain];
otherUnknownFieldData = [otherMsg->unknownFieldData_ retain]; otherUnknownFieldData = [otherMsg->unknownFieldData_ retain];
} }
#pragma clang diagnostic pop
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS) #if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
if (selfUnknownFields) { if (selfUnknownFields) {
NSAssert(selfUnknownFieldData == nil, @"Internal error both unknown states were set"); NSAssert(selfUnknownFieldData == nil, @"Internal error both unknown states were set");
@ -3189,6 +3205,8 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
result = [selfUnknownFields isEqual:otherUnknownFields]; result = [selfUnknownFields isEqual:otherUnknownFields];
} else { } else {
// At this point, we're done to one have a set/nothing, and the other having data/nothing. // At this point, we're done to one have a set/nothing, and the other having data/nothing.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *theSet = selfUnknownFields ? selfUnknownFields : otherUnknownFields; GPBUnknownFieldSet *theSet = selfUnknownFields ? selfUnknownFields : otherUnknownFields;
NSData *theData = selfUnknownFieldData ? selfUnknownFieldData : otherUnknownFieldData; NSData *theData = selfUnknownFieldData ? selfUnknownFieldData : otherUnknownFieldData;
if (theSet) { if (theSet) {
@ -3204,6 +3222,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
// It was a data/nothing and nothing, so they equal if the other didn't have data. // It was a data/nothing and nothing, so they equal if the other didn't have data.
result = theData == nil; result = theData == nil;
} }
#pragma clang diagnostic pop
} }
[selfUnknownFields release]; [selfUnknownFields release];
@ -4015,7 +4034,10 @@ id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
NSData *GPBMessageUnknownFieldsData(GPBMessage *self) { NSData *GPBMessageUnknownFieldsData(GPBMessage *self) {
NSData *result = nil; NSData *result = nil;
@synchronized(self) { @synchronized(self) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknownFields = self->unknownFields_; GPBUnknownFieldSet *unknownFields = self->unknownFields_;
#pragma clang diagnostic pop
if (unknownFields) { if (unknownFields) {
#if defined(DEBUG) && DEBUG #if defined(DEBUG) && DEBUG
NSCAssert(self->unknownFieldData_ == nil, @"Internal error both unknown states were set"); NSCAssert(self->unknownFieldData_ == nil, @"Internal error both unknown states were set");

@ -31,14 +31,15 @@ typedef NS_ENUM(uint8_t, GPBUnknownFieldType) {
}; };
/** /**
* Store an unknown field. These are used in conjunction with * Store an unknown field. These are used in conjunction with GPBUnknownFields.
* GPBUnknownFieldSet.
**/ **/
__attribute__((objc_subclassing_restricted)) __attribute__((objc_subclassing_restricted))
@interface GPBUnknownField : NSObject<NSCopying> @interface GPBUnknownField : NSObject<NSCopying>
/** Initialize a field with the given number. */ /** Initialize a field with the given number. */
- (instancetype)initWithNumber:(int32_t)number; - (instancetype)initWithNumber:(int32_t)number
__attribute__((deprecated(
"Use the apis on GPBUnknownFields to add new fields instead of making them directly.")));
/** The field number the data is stored under. */ /** The field number the data is stored under. */
@property(nonatomic, readonly, assign) int32_t number; @property(nonatomic, readonly, assign) int32_t number;
@ -88,7 +89,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* to use with any other type. * to use with any other type.
*/ */
@property(nonatomic, readonly, strong) GPBUInt64Array *varintList; @property(nonatomic, readonly, strong) GPBUInt64Array *varintList
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* An array of fixed32 values for this field. * An array of fixed32 values for this field.
@ -96,7 +98,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* to use with any other type. * to use with any other type.
*/ */
@property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List; @property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* An array of fixed64 values for this field. * An array of fixed64 values for this field.
@ -104,7 +107,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* to use with any other type. * to use with any other type.
*/ */
@property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List; @property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* An array of data values for this field. * An array of data values for this field.
@ -112,7 +116,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* to use with any other type. * to use with any other type.
*/ */
@property(nonatomic, readonly, strong) NSArray<NSData *> *lengthDelimitedList; @property(nonatomic, readonly, strong) NSArray<NSData *> *lengthDelimitedList
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* An array of groups of values for this field. * An array of groups of values for this field.
@ -120,7 +125,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* to use with any other type. * to use with any other type.
*/ */
@property(nonatomic, readonly, strong) NSArray<GPBUnknownFieldSet *> *groupList; @property(nonatomic, readonly, strong) NSArray<GPBUnknownFieldSet *> *groupList
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* Add a value to the varintList. * Add a value to the varintList.
@ -130,7 +136,9 @@ __attribute__((objc_subclassing_restricted))
* *
* @param value The value to add. * @param value The value to add.
**/ **/
- (void)addVarint:(uint64_t)value; - (void)addVarint:(uint64_t)value
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* Add a value to the fixed32List. * Add a value to the fixed32List.
* *
@ -139,7 +147,9 @@ __attribute__((objc_subclassing_restricted))
* *
* @param value The value to add. * @param value The value to add.
**/ **/
- (void)addFixed32:(uint32_t)value; - (void)addFixed32:(uint32_t)value
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* Add a value to the fixed64List. * Add a value to the fixed64List.
* *
@ -148,7 +158,9 @@ __attribute__((objc_subclassing_restricted))
* *
* @param value The value to add. * @param value The value to add.
**/ **/
- (void)addFixed64:(uint64_t)value; - (void)addFixed64:(uint64_t)value
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* Add a value to the lengthDelimitedList. * Add a value to the lengthDelimitedList.
* *
@ -157,7 +169,9 @@ __attribute__((objc_subclassing_restricted))
* *
* @param value The value to add. * @param value The value to add.
**/ **/
- (void)addLengthDelimited:(NSData *)value; - (void)addLengthDelimited:(NSData *)value
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
/** /**
* Add a value to the groupList. * Add a value to the groupList.
* *
@ -166,7 +180,8 @@ __attribute__((objc_subclassing_restricted))
* *
* @param value The value to add. * @param value The value to add.
**/ **/
- (void)addGroup:(GPBUnknownFieldSet *)value; - (void)addGroup:(GPBUnknownFieldSet *)value
__attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here.")));
@end @end

@ -169,6 +169,8 @@
// In these modes, the object isn't mutable, so just return self. // In these modes, the object isn't mutable, so just return self.
return [self retain]; return [self retain];
case GPBUnknownFieldTypeLegacy: { case GPBUnknownFieldTypeLegacy: {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownField *result = [[GPBUnknownField allocWithZone:zone] initWithNumber:number_]; GPBUnknownField *result = [[GPBUnknownField allocWithZone:zone] initWithNumber:number_];
result->storage_.legacy.mutableFixed32List = result->storage_.legacy.mutableFixed32List =
[storage_.legacy.mutableFixed32List copyWithZone:zone]; [storage_.legacy.mutableFixed32List copyWithZone:zone];
@ -187,6 +189,7 @@
[copied release]; [copied release];
} }
} }
#pragma clang diagnostic pop
return result; return result;
} }
} }
@ -264,6 +267,8 @@
} }
- (void)writeToOutput:(GPBCodedOutputStream *)output { - (void)writeToOutput:(GPBCodedOutputStream *)output {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy); ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy);
NSUInteger count = storage_.legacy.mutableVarintList.count; NSUInteger count = storage_.legacy.mutableVarintList.count;
if (count > 0) { if (count > 0) {
@ -285,10 +290,13 @@
if (count > 0) { if (count > 0) {
[output writeUnknownGroupArray:number_ values:storage_.legacy.mutableGroupList]; [output writeUnknownGroupArray:number_ values:storage_.legacy.mutableGroupList];
} }
#pragma clang diagnostic pop
} }
- (size_t)serializedSize { - (size_t)serializedSize {
ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy); ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
__block size_t result = 0; __block size_t result = 0;
int32_t number = number_; int32_t number = number_;
[storage_.legacy.mutableVarintList [storage_.legacy.mutableVarintList
@ -313,6 +321,7 @@
for (GPBUnknownFieldSet *set in storage_.legacy.mutableGroupList) { for (GPBUnknownFieldSet *set in storage_.legacy.mutableGroupList) {
result += GPBComputeUnknownGroupSize(number, set); result += GPBComputeUnknownGroupSize(number, set);
} }
#pragma clang diagnostic pop
return result; return result;
} }
@ -353,6 +362,8 @@
[description appendFormat:@" group: %@", storage_.group]; [description appendFormat:@" group: %@", storage_.group];
break; break;
case GPBUnknownFieldTypeLegacy: case GPBUnknownFieldTypeLegacy:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[description appendString:@" {\n"]; [description appendString:@" {\n"];
[storage_.legacy.mutableVarintList [storage_.legacy.mutableVarintList
enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) {
@ -373,12 +384,15 @@
[description appendFormat:@"\t%@\n", set]; [description appendFormat:@"\t%@\n", set];
} }
[description appendString:@"}"]; [description appendString:@"}"];
#pragma clang diagnostic pop
break; break;
} }
return description; return description;
} }
- (void)mergeFromField:(GPBUnknownField *)other { - (void)mergeFromField:(GPBUnknownField *)other {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy); ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy);
GPBUInt64Array *otherVarintList = other.varintList; GPBUInt64Array *otherVarintList = other.varintList;
if (otherVarintList.count > 0) { if (otherVarintList.count > 0) {
@ -429,6 +443,7 @@
[copied release]; [copied release];
} }
} }
#pragma clang diagnostic pop
} }
- (void)addVarint:(uint64_t)value { - (void)addVarint:(uint64_t)value {

@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
* A collection of unknown fields. Fields parsed from the binary representation * A collection of unknown fields. Fields parsed from the binary representation
* of a message that are unknown end up in an instance of this set. * of a message that are unknown end up in an instance of this set.
**/ **/
__attribute__((deprecated("Use GPBUnknownFields instead.", "GPBUnknownFields")))
__attribute__((objc_subclassing_restricted)) __attribute__((objc_subclassing_restricted))
@interface GPBUnknownFieldSet : NSObject<NSCopying> @interface GPBUnknownFieldSet : NSObject<NSCopying>

@ -13,6 +13,10 @@
#import "GPBUtilities.h" #import "GPBUtilities.h"
#import "GPBWireFormat.h" #import "GPBWireFormat.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
#pragma mark Helpers #pragma mark Helpers
static void checkNumber(int32_t number) { static void checkNumber(int32_t number) {
@ -154,10 +158,7 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex
- (NSString *)description { - (NSString *)description {
NSMutableString *description = NSMutableString *description =
[NSMutableString stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self]; [NSMutableString stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSString *textFormat = GPBTextFormatForUnknownFieldSet(self, @" "); NSString *textFormat = GPBTextFormatForUnknownFieldSet(self, @" ");
#pragma clang diagnostic pop
[description appendString:textFormat]; [description appendString:textFormat];
[description appendString:@"}"]; [description appendString:@"}"];
return description; return description;
@ -340,3 +341,5 @@ static void GPBUnknownFieldSetMergeUnknownFields(__unused const void *key, const
#pragma clang diagnostic pop #pragma clang diagnostic pop
@end @end
#pragma clang diagnostic pop // -Wdeprecated-declarations suppression

@ -25,7 +25,10 @@
GPBUInt32Array *_Null_unspecified mutableFixed32List; GPBUInt32Array *_Null_unspecified mutableFixed32List;
GPBUInt64Array *_Null_unspecified mutableFixed64List; GPBUInt64Array *_Null_unspecified mutableFixed64List;
NSMutableArray<NSData *> *_Null_unspecified mutableLengthDelimitedList; NSMutableArray<NSData *> *_Null_unspecified mutableLengthDelimitedList;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSMutableArray<GPBUnknownFieldSet *> *_Null_unspecified mutableGroupList; NSMutableArray<GPBUnknownFieldSet *> *_Null_unspecified mutableGroupList;
#pragma clang diagnostic pop
} legacy; } legacy;
} storage_; } storage_;
} }

@ -305,7 +305,10 @@
// skipping as expected (this covers the tags within a group also). // skipping as expected (this covers the tags within a group also).
GPBCodedInputStream* input1 = [GPBCodedInputStream streamWithData:rawBytes]; GPBCodedInputStream* input1 = [GPBCodedInputStream streamWithData:rawBytes];
GPBCodedInputStream* input2 = [GPBCodedInputStream streamWithData:rawBytes]; GPBCodedInputStream* input2 = [GPBCodedInputStream streamWithData:rawBytes];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet* unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownFieldSet* unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease];
#pragma clang diagnostic pop
NSUInteger idx = 0; NSUInteger idx = 0;
while (YES) { while (YES) {

@ -430,6 +430,9 @@
XCTAssertEqual(varint, (uint64_t)Message3_Enum_Extra3); XCTAssertEqual(varint, (uint64_t)Message3_Enum_Extra3);
[ufs release]; [ufs release];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknownFields = msg.unknownFields; GPBUnknownFieldSet *unknownFields = msg.unknownFields;
XCTAssertEqual([unknownFields countOfFields], 3U); XCTAssertEqual([unknownFields countOfFields], 3U);
@ -449,6 +452,8 @@
XCTAssertEqual(field.varintList.count, 1U); XCTAssertEqual(field.varintList.count, 1U);
XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3); XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3);
#pragma clang diagnostic pop
[msg release]; [msg release];
[orig release]; [orig release];
} }
@ -1412,7 +1417,10 @@
GPBUnknownFields *ufs = [[GPBUnknownFields alloc] initFromMessage:msg1]; GPBUnknownFields *ufs = [[GPBUnknownFields alloc] initFromMessage:msg1];
XCTAssertEqual(ufs.count, 1U); XCTAssertEqual(ufs.count, 1U);
[ufs release]; [ufs release];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(msg1.unknownFields.countOfFields, 1U); XCTAssertEqual(msg1.unknownFields.countOfFields, 1U);
#pragma clang diagnostic pop
data = [msg1 data]; data = [msg1 data];
TestEnumMapPlusExtra *msg2 = [TestEnumMapPlusExtra parseFromData:data error:NULL]; TestEnumMapPlusExtra *msg2 = [TestEnumMapPlusExtra parseFromData:data error:NULL];
@ -1427,7 +1435,10 @@
ufs = [[GPBUnknownFields alloc] initFromMessage:msg2]; ufs = [[GPBUnknownFields alloc] initFromMessage:msg2];
XCTAssertTrue(ufs.empty); XCTAssertTrue(ufs.empty);
[ufs release]; [ufs release];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(msg2.unknownFields.countOfFields, 0U); XCTAssertEqual(msg2.unknownFields.countOfFields, 0U);
#pragma clang diagnostic pop
XCTAssertEqualObjects(orig, msg2); XCTAssertEqualObjects(orig, msg2);

@ -493,6 +493,8 @@
TestAllTypes *message = [TestAllTypes message]; TestAllTypes *message = [TestAllTypes message];
[self setAllFields:message repeatedCount:kGPBDefaultRepeatCount]; [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownFieldSet *unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease];
GPBUnknownField *field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease]; GPBUnknownField *field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
[field addVarint:2]; [field addVarint:2];
@ -502,6 +504,7 @@
[unknownFields addField:field]; [unknownFields addField:field];
[message setUnknownFields:unknownFields]; [message setUnknownFields:unknownFields];
#pragma clang diagnostic pop
GPBUnknownFields *ufs = [[[GPBUnknownFields alloc] init] autorelease]; GPBUnknownFields *ufs = [[[GPBUnknownFields alloc] init] autorelease];
[ufs addFieldNumber:1234 fixed32:1234]; [ufs addFieldNumber:1234 fixed32:1234];
@ -976,6 +979,9 @@
} }
- (void)testAutocreatedUnknownFields { - (void)testAutocreatedUnknownFields {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Doing anything with (except reading) unknown fields should cause the // Doing anything with (except reading) unknown fields should cause the
// submessage to become visible. // submessage to become visible.
TestAllTypes *message = [TestAllTypes message]; TestAllTypes *message = [TestAllTypes message];
@ -1009,6 +1015,8 @@
extensionRegistry:nil extensionRegistry:nil
error:NULL]); error:NULL]);
XCTAssertTrue([message hasOptionalNestedMessage]); XCTAssertTrue([message hasOptionalNestedMessage]);
#pragma clang diagnostic pop
} }
- (void)testSetAutocreatedSubmessageToSelf { - (void)testSetAutocreatedSubmessageToSelf {
@ -1518,6 +1526,8 @@
varint:&varint]); varint:&varint]);
XCTAssertEqual(varint, 12); XCTAssertEqual(varint, 12);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknownFields = msg.unknownFields; GPBUnknownFieldSet *unknownFields = msg.unknownFields;
GPBUnknownField *field = GPBUnknownField *field =
[unknownFields getField:[UnittestRoot optionalNestedEnumExtension].fieldNumber]; [unknownFields getField:[UnittestRoot optionalNestedEnumExtension].fieldNumber];
@ -1532,6 +1542,7 @@
XCTAssertNotNil(field); XCTAssertNotNil(field);
XCTAssertEqual(field.varintList.count, 1); XCTAssertEqual(field.varintList.count, 1);
XCTAssertEqual([field.varintList valueAtIndex:0], 12); XCTAssertEqual([field.varintList valueAtIndex:0], 12);
#pragma clang diagnostic pop
// Unknown and known, the known come though an unknown go to unknown fields. // Unknown and known, the known come though an unknown go to unknown fields.
@ -1572,6 +1583,8 @@
varint:&varint]); varint:&varint]);
XCTAssertEqual(varint, 12); XCTAssertEqual(varint, 12);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
unknownFields = msg.unknownFields; unknownFields = msg.unknownFields;
field = [unknownFields getField:[UnittestRoot optionalNestedEnumExtension].fieldNumber]; field = [unknownFields getField:[UnittestRoot optionalNestedEnumExtension].fieldNumber];
XCTAssertNotNil(field); XCTAssertNotNil(field);
@ -1585,6 +1598,7 @@
XCTAssertNotNil(field); XCTAssertNotNil(field);
XCTAssertEqual(field.varintList.count, 1); XCTAssertEqual(field.varintList.count, 1);
XCTAssertEqual([field.varintList valueAtIndex:0], 12); XCTAssertEqual([field.varintList valueAtIndex:0], 12);
#pragma clang diagnostic pop
} }
- (void)testDefaultingExtensionMessages { - (void)testDefaultingExtensionMessages {
@ -1885,10 +1899,13 @@
} }
- (void)testGenerateAndParseUnknownMessage { - (void)testGenerateAndParseUnknownMessage {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknowns = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownFieldSet *unknowns = [[[GPBUnknownFieldSet alloc] init] autorelease];
[unknowns mergeVarintField:123 value:456]; [unknowns mergeVarintField:123 value:456];
GPBMessage *message = [GPBMessage message]; GPBMessage *message = [GPBMessage message];
[message setUnknownFields:unknowns]; [message setUnknownFields:unknowns];
#pragma clang diagnostic pop
GPBUnknownFields *ufs = [[[GPBUnknownFields alloc] init] autorelease]; GPBUnknownFields *ufs = [[[GPBUnknownFields alloc] init] autorelease];
[ufs addFieldNumber:1234 varint:5678]; [ufs addFieldNumber:1234 varint:5678];
XCTAssertTrue([message mergeUnknownFields:ufs extensionRegistry:nil error:NULL]); XCTAssertTrue([message mergeUnknownFields:ufs extensionRegistry:nil error:NULL]);
@ -1898,19 +1915,25 @@
} }
- (void)testDelimitedWriteAndParseMultipleMessages { - (void)testDelimitedWriteAndParseMultipleMessages {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknowns1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownFieldSet *unknowns1 = [[[GPBUnknownFieldSet alloc] init] autorelease];
[unknowns1 mergeVarintField:123 value:456]; [unknowns1 mergeVarintField:123 value:456];
GPBMessage *message1 = [GPBMessage message]; GPBMessage *message1 = [GPBMessage message];
[message1 setUnknownFields:unknowns1]; [message1 setUnknownFields:unknowns1];
#pragma clang diagnostic pop
GPBUnknownFields *ufs1 = [[[GPBUnknownFields alloc] init] autorelease]; GPBUnknownFields *ufs1 = [[[GPBUnknownFields alloc] init] autorelease];
[ufs1 addFieldNumber:1234 varint:5678]; [ufs1 addFieldNumber:1234 varint:5678];
XCTAssertTrue([message1 mergeUnknownFields:ufs1 extensionRegistry:nil error:NULL]); XCTAssertTrue([message1 mergeUnknownFields:ufs1 extensionRegistry:nil error:NULL]);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknowns2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownFieldSet *unknowns2 = [[[GPBUnknownFieldSet alloc] init] autorelease];
[unknowns2 mergeVarintField:789 value:987]; [unknowns2 mergeVarintField:789 value:987];
[unknowns2 mergeVarintField:654 value:321]; [unknowns2 mergeVarintField:654 value:321];
GPBMessage *message2 = [GPBMessage message]; GPBMessage *message2 = [GPBMessage message];
[message2 setUnknownFields:unknowns2]; [message2 setUnknownFields:unknowns2];
#pragma clang diagnostic pop
GPBUnknownFields *ufs2 = [[[GPBUnknownFields alloc] init] autorelease]; GPBUnknownFields *ufs2 = [[[GPBUnknownFields alloc] init] autorelease];
[ufs2 addFieldNumber:2345 fixed32:6789]; [ufs2 addFieldNumber:2345 fixed32:6789];
[ufs2 addFieldNumber:3456 fixed32:7890]; [ufs2 addFieldNumber:3456 fixed32:7890];
@ -2111,6 +2134,8 @@
XCTAssertEqual(fields[0].varint, (uint64_t)EnumTestMsg_MyEnum_Two); XCTAssertEqual(fields[0].varint, (uint64_t)EnumTestMsg_MyEnum_Two);
XCTAssertEqual(fields[1].varint, (uint64_t)EnumTestMsg_MyEnum_NegTwo); XCTAssertEqual(fields[1].varint, (uint64_t)EnumTestMsg_MyEnum_NegTwo);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknownFields = msg2.unknownFields; GPBUnknownFieldSet *unknownFields = msg2.unknownFields;
XCTAssertNotNil(unknownFields); XCTAssertNotNil(unknownFields);
XCTAssertEqual(unknownFields.countOfFields, 3U); XCTAssertEqual(unknownFields.countOfFields, 3U);
@ -2127,6 +2152,7 @@
XCTAssertEqual(field.varintList.count, 2U); XCTAssertEqual(field.varintList.count, 2U);
XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)EnumTestMsg_MyEnum_Two); XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)EnumTestMsg_MyEnum_Two);
XCTAssertEqual([field.varintList valueAtIndex:1], (uint64_t)EnumTestMsg_MyEnum_NegTwo); XCTAssertEqual([field.varintList valueAtIndex:1], (uint64_t)EnumTestMsg_MyEnum_NegTwo);
#pragma clang diagnostic pop
} }
- (void)testReservedWordNaming { - (void)testReservedWordNaming {

@ -12,6 +12,9 @@
#import "GPBUnknownField_PackagePrivate.h" #import "GPBUnknownField_PackagePrivate.h"
#import "objectivec/Tests/Unittest.pbobjc.h" #import "objectivec/Tests/Unittest.pbobjc.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@interface GPBUnknownFieldSet (GPBUnknownFieldSetTest) @interface GPBUnknownFieldSet (GPBUnknownFieldSetTest)
- (void)getTags:(int32_t*)tags; - (void)getTags:(int32_t*)tags;
@end @end
@ -668,3 +671,5 @@ static NSData* DataForGroupsOfDepth(NSUInteger depth) {
} }
@end @end
#pragma clang diagnostic pop

@ -911,16 +911,32 @@
} }
- (void)testMergeFailures { - (void)testMergeFailures {
// Valid data, pushes to the string just fine. // Valid data, pushes to the fields just fine.
{ {
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease];
[ufs addFieldNumber:TestAllTypes_FieldNumber_OptionalString [ufs addFieldNumber:TestAllTypes_FieldNumber_OptionalString
lengthDelimited:DataFromCStr("abc")]; lengthDelimited:DataFromCStr("abc")];
[ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedInt32Array
lengthDelimited:DataFromBytes(0x01, 0x02)];
[ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedFixed32Array
lengthDelimited:DataFromBytes(0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00)];
[ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedFixed64Array
lengthDelimited:DataFromBytes(0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00)];
TestAllTypes* msg = [TestAllTypes message]; TestAllTypes* msg = [TestAllTypes message];
NSError* error = nil; NSError* error = nil;
XCTAssertTrue([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); XCTAssertTrue([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]);
XCTAssertNil(error); XCTAssertNil(error);
XCTAssertEqualObjects(msg.optionalString, @"abc"); XCTAssertEqualObjects(msg.optionalString, @"abc");
XCTAssertEqual(msg.repeatedInt32Array.count, 2);
XCTAssertEqual([msg.repeatedInt32Array valueAtIndex:0], 1);
XCTAssertEqual([msg.repeatedInt32Array valueAtIndex:1], 2);
XCTAssertEqual(msg.repeatedFixed32Array.count, 2);
XCTAssertEqual([msg.repeatedFixed32Array valueAtIndex:0], 3);
XCTAssertEqual([msg.repeatedFixed32Array valueAtIndex:1], 4);
XCTAssertEqual(msg.repeatedFixed64Array.count, 2);
XCTAssertEqual([msg.repeatedFixed64Array valueAtIndex:0], 5);
XCTAssertEqual([msg.repeatedFixed64Array valueAtIndex:1], 6);
} }
// Invalid UTF-8 causes a failure when pushed to the message. // Invalid UTF-8 causes a failure when pushed to the message.
@ -933,6 +949,39 @@
XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]);
XCTAssertNotNil(error); XCTAssertNotNil(error);
} }
// Invalid packed varint causes a failure when pushed to the message.
{
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease];
[ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedInt32Array
lengthDelimited:DataFromBytes(0xff)]; // Invalid varint
TestAllTypes* msg = [TestAllTypes message];
NSError* error = nil;
XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]);
XCTAssertNotNil(error);
}
// Invalid packed fixed32 causes a failure when pushed to the message.
{
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease];
[ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedFixed32Array
lengthDelimited:DataFromBytes(0x01, 0x00, 0x00)]; // Truncated fixed32
TestAllTypes* msg = [TestAllTypes message];
NSError* error = nil;
XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]);
XCTAssertNotNil(error);
}
// Invalid packed fixed64 causes a failure when pushed to the message.
{
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease];
[ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedFixed64Array
lengthDelimited:DataFromBytes(0x01, 0x00, 0x00, 0x00, 0x00)]; // Truncated fixed64
TestAllTypes* msg = [TestAllTypes message];
NSError* error = nil;
XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]);
XCTAssertNotNil(error);
}
} }
- (void)testLargeVarint { - (void)testLargeVarint {

@ -240,6 +240,8 @@
} }
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Helper to make an unknown field set with something in it. // Helper to make an unknown field set with something in it.
static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) {
GPBUnknownFieldSet *result = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownFieldSet *result = [[[GPBUnknownFieldSet alloc] init] autorelease];
@ -250,6 +252,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) {
return result; return result;
} }
#pragma clang diagnostic pop
// Helper to add an unknown field data to messages. // Helper to add an unknown field data to messages.
static void AddUnknownFields(GPBMessage *message, int num) { static void AddUnknownFields(GPBMessage *message, int num) {
@ -270,6 +273,9 @@ static BOOL HasUnknownFields(GPBMessage *message) {
- (void)testDropMessageUnknownFieldsRecursively { - (void)testDropMessageUnknownFieldsRecursively {
TestAllExtensions *message = [TestAllExtensions message]; TestAllExtensions *message = [TestAllExtensions message];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Give it unknownFields. // Give it unknownFields.
message.unknownFields = UnknownFieldsSetHelper(777); message.unknownFields = UnknownFieldsSetHelper(777);
AddUnknownFields(message, 1777); AddUnknownFields(message, 1777);
@ -412,11 +418,16 @@ static BOOL HasUnknownFields(GPBMessage *message) {
XCTAssertFalse(HasUnknownFields(repeatedNestedMessage)); XCTAssertFalse(HasUnknownFields(repeatedNestedMessage));
XCTAssertNil(repeatedNestedMessage.unknownFields); XCTAssertNil(repeatedNestedMessage.unknownFields);
} }
#pragma clang diagnostic pop
} }
- (void)testDropMessageUnknownFieldsRecursively_Maps { - (void)testDropMessageUnknownFieldsRecursively_Maps {
TestMap *message = [TestMap message]; TestMap *message = [TestMap message];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
{ {
ForeignMessage *foreignMessage = [ForeignMessage message]; ForeignMessage *foreignMessage = [ForeignMessage message];
foreignMessage.unknownFields = UnknownFieldsSetHelper(100); foreignMessage.unknownFields = UnknownFieldsSetHelper(100);
@ -466,6 +477,8 @@ static BOOL HasUnknownFields(GPBMessage *message) {
XCTAssertFalse(HasUnknownFields(foreignMessage)); XCTAssertFalse(HasUnknownFields(foreignMessage));
XCTAssertNil(foreignMessage.unknownFields); XCTAssertNil(foreignMessage.unknownFields);
} }
#pragma clang diagnostic pop
} }
@end @end

@ -120,12 +120,15 @@ const int kUnknownTypeId2 = 1550056;
[[message_set getExtension:[MSetMessageExtension1 messageSetExtension]] setI:123]; [[message_set getExtension:[MSetMessageExtension1 messageSetExtension]] setI:123];
[[message_set getExtension:[MSetMessageExtension2 messageSetExtension]] setStr:@"foo"]; [[message_set getExtension:[MSetMessageExtension2 messageSetExtension]] setStr:@"foo"];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownField* unknownField = GPBUnknownField* unknownField =
[[[GPBUnknownField alloc] initWithNumber:kUnknownTypeId] autorelease]; [[[GPBUnknownField alloc] initWithNumber:kUnknownTypeId] autorelease];
[unknownField addLengthDelimited:DataFromCStr("bar")]; [unknownField addLengthDelimited:DataFromCStr("bar")];
GPBUnknownFieldSet* unknownFieldSet = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownFieldSet* unknownFieldSet = [[[GPBUnknownFieldSet alloc] init] autorelease];
[unknownFieldSet addField:unknownField]; [unknownFieldSet addField:unknownField];
[message_set setUnknownFields:unknownFieldSet]; [message_set setUnknownFields:unknownFieldSet];
#pragma clang diagnostic pop
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease];
GPBUnknownFields* group = [ufs addGroupWithFieldNumber:GPBWireFormatMessageSetItem]; GPBUnknownFields* group = [ufs addGroupWithFieldNumber:GPBWireFormatMessageSetItem];
@ -142,7 +145,10 @@ const int kUnknownTypeId2 = 1550056;
GPBUnknownFields* ufs2 = [[[GPBUnknownFields alloc] initFromMessage:raw] autorelease]; GPBUnknownFields* ufs2 = [[[GPBUnknownFields alloc] initFromMessage:raw] autorelease];
XCTAssertTrue(ufs2.empty); XCTAssertTrue(ufs2.empty);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual([raw.unknownFields countOfFields], (NSUInteger)0); XCTAssertEqual([raw.unknownFields countOfFields], (NSUInteger)0);
#pragma clang diagnostic pop
XCTAssertEqual(raw.itemArray.count, (NSUInteger)4); XCTAssertEqual(raw.itemArray.count, (NSUInteger)4);
XCTAssertEqual((uint32_t)[raw.itemArray[0] typeId], XCTAssertEqual((uint32_t)[raw.itemArray[0] typeId],
@ -217,11 +223,14 @@ const int kUnknownTypeId2 = 1550056;
XCTAssertEqualObjects([group firstLengthDelimited:GPBWireFormatMessageSetMessage], XCTAssertEqualObjects([group firstLengthDelimited:GPBWireFormatMessageSetMessage],
DataFromCStr("bar")); DataFromCStr("bar"));
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual([messageSet.unknownFields countOfFields], (NSUInteger)1); XCTAssertEqual([messageSet.unknownFields countOfFields], (NSUInteger)1);
GPBUnknownField* unknownField = [messageSet.unknownFields getField:kUnknownTypeId]; GPBUnknownField* unknownField = [messageSet.unknownFields getField:kUnknownTypeId];
XCTAssertNotNil(unknownField); XCTAssertNotNil(unknownField);
XCTAssertEqual(unknownField.lengthDelimitedList.count, (NSUInteger)1); XCTAssertEqual(unknownField.lengthDelimitedList.count, (NSUInteger)1);
XCTAssertEqualObjects(unknownField.lengthDelimitedList[0], DataFromCStr("bar")); XCTAssertEqualObjects(unknownField.lengthDelimitedList[0], DataFromCStr("bar"));
#pragma clang diagnostic pop
} }
- (void)testParseMessageSet_FirstValueSticks { - (void)testParseMessageSet_FirstValueSticks {

Loading…
Cancel
Save