[ObjC] Add `-[GPBMessage clearUnknownFields]`.

This is in preparation for revising the Unknown Fields related apis.

PiperOrigin-RevId: 647693027
pull/17271/head
Thomas Van Lenten 7 months ago committed by Copybara-Service
parent 10c00b82af
commit de29e3c9ae
  1. 9
      objectivec/GPBMessage.h
  2. 4
      objectivec/GPBMessage.m
  3. 2
      objectivec/GPBUtilities.m

@ -493,6 +493,15 @@ CF_EXTERN_C_END
**/
- (void)clear;
/**
* Clears any unknown fields on this message.
*
* Note: To clear this message's unknown field and all the unknown fields of the
* messages within the fields of this message, use
* `GPBMessageDropUnknownFieldsRecursively()`.
**/
- (void)clearUnknownFields;
@end
NS_ASSUME_NONNULL_END

@ -1251,6 +1251,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
}
- (void)clearUnknownFields {
self.unknownFields = nil;
}
- (BOOL)isInitialized {
GPBDescriptor *descriptor = [self descriptor];
for (GPBFieldDescriptor *field in descriptor->fields_) {

@ -63,7 +63,7 @@ void GPBMessageDropUnknownFieldsRecursively(GPBMessage *initialMessage) {
[todo removeLastObject];
// Clear unknowns.
msg.unknownFields = nil;
[msg clearUnknownFields];
// Handle the message fields.
GPBDescriptor *descriptor = [[msg class] descriptor];

Loading…
Cancel
Save