[ObjC] Deprecate GPBUnknownFieldSet and related apis.

GPBUnknownFields will be going away in the next major release of the ObjC
Protobuf runtime. Code should be updated to make use of GPBUnknownFields
instead.

PiperOrigin-RevId: 659963056
pull/17703/head
Thomas Van Lenten 4 months ago committed by Copybara-Service
parent 1492fa9598
commit d794139f09
  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. 8
      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. 13
      objectivec/Tests/GPBUtilitiesTests.m
  18. 9
      objectivec/Tests/GPBWireFormatTests.m

@ -494,6 +494,8 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t
--state_.recursionDepth;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message {
CheckRecursionLimit(&state_);
++state_.recursionDepth;
@ -502,6 +504,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t
GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
--state_.recursionDepth;
}
#pragma clang diagnostic pop
- (void)readMessage:(GPBMessage *)message
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
// UnknownFieldSet.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message;
#pragma clang diagnostic pop
// Reads a map entry.
- (void)readMapEntry:(id)mapDictionary

@ -589,6 +589,10 @@ __attribute__((objc_subclassing_restricted))
- (void)writeGroupNoTag:(int32_t)fieldNumber
value:(GPBMessage *)value;
//%PDDM-EXPAND-END _WRITE_DECLS()
// clang-format on
/**
* Write a GPBUnknownFieldSet for the given field number.
*
@ -596,7 +600,9 @@ __attribute__((objc_subclassing_restricted))
* @param value The value to write out.
**/
- (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.
*
@ -604,7 +610,9 @@ __attribute__((objc_subclassing_restricted))
* @param values The values to write out.
**/
- (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).
*
@ -612,11 +620,8 @@ __attribute__((objc_subclassing_restricted))
* @param value The value to write out.
**/
- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber
value:(GPBUnknownFieldSet *)value;
//%PDDM-EXPAND-END _WRITE_DECLS()
// clang-format on
value:(GPBUnknownFieldSet *)value
__attribute__((deprecated("GPBUnknownFieldSet is going away.")));
/**
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(Bytes, NSData)
//%_WRITE_GROUP_DECLS(Group, GPBMessage)
//%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet)
// clang-format on

@ -352,6 +352,9 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t 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 {
[value writeToCodedOutputStream:self];
GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup);
@ -362,6 +365,8 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value
[self writeUnknownGroupNoTag:fieldNumber value:value];
}
#pragma clang diagnostic pop
- (void)writeMessageNoTag:(GPBMessage *)value {
GPBWriteRawVarint32(&state_, (int32_t)[value serializedSize]);
[value writeToCodedOutputStream:self];
@ -838,8 +843,12 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value
}
}
//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(UnknownGroup, GPBUnknownFieldSet)
// This block of code is generated, do not edit it directly.
//%PDDM-EXPAND-END (19 expansions)
// clang-format on
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values {
for (GPBUnknownFieldSet *value in values) {
@ -847,9 +856,7 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value
}
}
//%PDDM-EXPAND-END (19 expansions)
// clang-format on
#pragma clang diagnostic pop
- (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value {
GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatStartGroup);
@ -982,7 +989,10 @@ size_t GPBComputeStringSizeNoTag(NSString *value) {
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; }
#pragma clang diagnostic pop
size_t GPBComputeMessageSizeNoTag(GPBMessage *value) {
size_t size = [value serializedSize];
@ -1050,9 +1060,12 @@ size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *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) {
return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeUnknownGroupSizeNoTag(value);
}
#pragma clang diagnostic pop
size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *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 GPBComputeStringSize(int32_t fieldNumber, NSString *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)
__attribute__((const));
#pragma clang diagnostic pop
size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const));
size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *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 GPBComputeStringSizeNoTag(NSString *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));
#pragma clang diagnostic pop
size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const));
size_t GPBComputeBytesSizeNoTag(NSData *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
* property of two other messages.
*
* @note While the class support NSSecureCoding, if the message has any
* extensions, they will end up reloaded in @c unknownFields as there is
* @note While the class supports NSSecureCoding, if the message has any
* extensions, they will end up reloaded in the unknown fields as there is
* no way for the @c NSCoding plumbing to pass through a
* @c GPBExtensionRegistry. To support extensions, instead of passing the
* 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.
**/
@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

@ -79,7 +79,10 @@ NSString *const GPBMessageExceptionMessageTooLarge =
// be protected with an @synchronized(self) block (that way the code also doesn't have to
// worry about throws).
NSMutableData *unknownFieldData_;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknownFields_;
#pragma clang diagnostic pop
NSMutableDictionary *extensionMap_;
// Readonly access to autocreatedExtensionMap_ is protected via readOnlyLock_.
@ -1106,6 +1109,8 @@ void GPBClearMessageAutocreator(GPBMessage *self) {
self->autocreatorExtension_ = nil;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPB_NOINLINE
static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
GPBUnknownFieldSet *targetSet) {
@ -1151,6 +1156,7 @@ static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
[decodeInto release];
}
}
#pragma clang diagnostic pop
@implementation GPBMessage
@ -1481,7 +1487,14 @@ static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
}
- (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
@ -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)
// so we have a version to compare against safely incase the second access causes the transform
// between internal states.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *selfUnknownFields;
NSData *selfUnknownFieldData;
@synchronized(self) {
@ -3161,6 +3176,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
otherUnknownFields = [otherMsg->unknownFields_ retain];
otherUnknownFieldData = [otherMsg->unknownFieldData_ retain];
}
#pragma clang diagnostic pop
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
if (selfUnknownFields) {
NSAssert(selfUnknownFieldData == nil, @"Internal error both unknown states were set");
@ -3189,6 +3205,8 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
result = [selfUnknownFields isEqual:otherUnknownFields];
} else {
// 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;
NSData *theData = selfUnknownFieldData ? selfUnknownFieldData : otherUnknownFieldData;
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.
result = theData == nil;
}
#pragma clang diagnostic pop
}
[selfUnknownFields release];
@ -4015,7 +4034,10 @@ id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
NSData *GPBMessageUnknownFieldsData(GPBMessage *self) {
NSData *result = nil;
@synchronized(self) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBUnknownFieldSet *unknownFields = self->unknownFields_;
#pragma clang diagnostic pop
if (unknownFields) {
#if defined(DEBUG) && DEBUG
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
* GPBUnknownFieldSet.
* Store an unknown field. These are used in conjunction with GPBUnknownFields.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBUnknownField : NSObject<NSCopying>
/** 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. */
@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
* 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.
@ -96,7 +98,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* 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.
@ -104,7 +107,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* 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.
@ -112,7 +116,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* 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.
@ -120,7 +125,8 @@ __attribute__((objc_subclassing_restricted))
* Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error
* 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.
@ -130,7 +136,9 @@ __attribute__((objc_subclassing_restricted))
*
* @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.
*
@ -139,7 +147,9 @@ __attribute__((objc_subclassing_restricted))
*
* @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.
*
@ -148,7 +158,9 @@ __attribute__((objc_subclassing_restricted))
*
* @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.
*
@ -157,7 +169,9 @@ __attribute__((objc_subclassing_restricted))
*
* @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.
*
@ -166,7 +180,8 @@ __attribute__((objc_subclassing_restricted))
*
* @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

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

@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
* 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.
**/
__attribute__((deprecated("Use GPBUnknownFields instead.", "GPBUnknownFields")))
__attribute__((objc_subclassing_restricted))
@interface GPBUnknownFieldSet : NSObject<NSCopying>

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

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

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

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

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

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

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

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

Loading…
Cancel
Save