|
@@ -62,6 +62,12 @@ static GPBDataType BaseDataType(GPBDataType type) __attribute__ ((unused));
|
|
// Marked unused because currently only called from asserts/debug.
|
|
// Marked unused because currently only called from asserts/debug.
|
|
static NSString *TypeToString(GPBDataType dataType) __attribute__ ((unused));
|
|
static NSString *TypeToString(GPBDataType dataType) __attribute__ ((unused));
|
|
|
|
|
|
|
|
+// Helper for clearing oneofs.
|
|
|
|
+static void GPBMaybeClearOneofPrivate(GPBMessage *self,
|
|
|
|
+ GPBOneofDescriptor *oneof,
|
|
|
|
+ int32_t oneofHasIndex,
|
|
|
|
+ uint32_t fieldNumberNotToClear);
|
|
|
|
+
|
|
NSData *GPBEmptyNSData(void) {
|
|
NSData *GPBEmptyNSData(void) {
|
|
static dispatch_once_t onceToken;
|
|
static dispatch_once_t onceToken;
|
|
static NSData *defaultNSData = nil;
|
|
static NSData *defaultNSData = nil;
|
|
@@ -267,17 +273,28 @@ void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
if (GPBFieldStoresObject(field)) {
|
|
if (GPBFieldStoresObject(field)) {
|
|
// Object types are handled slightly differently, they need to be released.
|
|
// Object types are handled slightly differently, they need to be released.
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
- id *typePtr = (id *)&storage[field->description_->offset];
|
|
|
|
|
|
+ id *typePtr = (id *)&storage[fieldDesc->offset];
|
|
[*typePtr release];
|
|
[*typePtr release];
|
|
*typePtr = nil;
|
|
*typePtr = nil;
|
|
} else {
|
|
} else {
|
|
// POD types just need to clear the has bit as the Get* method will
|
|
// POD types just need to clear the has bit as the Get* method will
|
|
// fetch the default when needed.
|
|
// fetch the default when needed.
|
|
}
|
|
}
|
|
- GPBSetHasIvarField(self, field, NO);
|
|
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, NO);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof) {
|
|
|
|
+ #if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] oneofWithName:oneof.name] == oneof,
|
|
|
|
+ @"OneofDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ oneof.name, [self class]);
|
|
|
|
+ #endif
|
|
|
|
+ GPBFieldDescriptor *firstField = oneof->fields_[0];
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, firstField->description_->hasIndex, 0);
|
|
}
|
|
}
|
|
|
|
|
|
BOOL GPBGetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber) {
|
|
BOOL GPBGetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber) {
|
|
@@ -324,8 +341,10 @@ void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
|
|
|
|
- int32_t oneofHasIndex, uint32_t fieldNumberNotToClear) {
|
|
|
|
|
|
+static void GPBMaybeClearOneofPrivate(GPBMessage *self,
|
|
|
|
+ GPBOneofDescriptor *oneof,
|
|
|
|
+ int32_t oneofHasIndex,
|
|
|
|
+ uint32_t fieldNumberNotToClear) {
|
|
uint32_t fieldNumberSet = GPBGetHasOneof(self, oneofHasIndex);
|
|
uint32_t fieldNumberSet = GPBGetHasOneof(self, oneofHasIndex);
|
|
if ((fieldNumberSet == fieldNumberNotToClear) || (fieldNumberSet == 0)) {
|
|
if ((fieldNumberSet == fieldNumberNotToClear) || (fieldNumberSet == 0)) {
|
|
// Do nothing/nothing set in the oneof.
|
|
// Do nothing/nothing set in the oneof.
|
|
@@ -356,6 +375,9 @@ void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
|
|
//%TYPE GPBGetMessage##NAME##Field(GPBMessage *self,
|
|
//%TYPE GPBGetMessage##NAME##Field(GPBMessage *self,
|
|
//% TYPE$S NAME$S GPBFieldDescriptor *field) {
|
|
//% TYPE$S NAME$S GPBFieldDescriptor *field) {
|
|
//%#if defined(DEBUG) && DEBUG
|
|
//%#if defined(DEBUG) && DEBUG
|
|
|
|
+//% NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+//% @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+//% field.name, [self class]);
|
|
//% NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
//% NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
//% GPBDataType##NAME),
|
|
//% GPBDataType##NAME),
|
|
//% @"Attempting to get value of TYPE from field %@ "
|
|
//% @"Attempting to get value of TYPE from field %@ "
|
|
@@ -377,15 +399,10 @@ void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
|
|
//% NAME$S GPBFieldDescriptor *field,
|
|
//% NAME$S GPBFieldDescriptor *field,
|
|
//% NAME$S TYPE value) {
|
|
//% NAME$S TYPE value) {
|
|
//% if (self == nil || field == nil) return;
|
|
//% if (self == nil || field == nil) return;
|
|
-//% GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
-//% GPBSet##NAME##IvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-//%}
|
|
|
|
-//%
|
|
|
|
-//%void GPBSet##NAME##IvarWithFieldInternal(GPBMessage *self,
|
|
|
|
-//% NAME$S GPBFieldDescriptor *field,
|
|
|
|
-//% NAME$S TYPE value,
|
|
|
|
-//% NAME$S GPBFileSyntax syntax) {
|
|
|
|
//%#if defined(DEBUG) && DEBUG
|
|
//%#if defined(DEBUG) && DEBUG
|
|
|
|
+//% NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+//% @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+//% field.name, [self class]);
|
|
//% NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
//% NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
//% GPBDataType##NAME),
|
|
//% GPBDataType##NAME),
|
|
//% @"Attempting to set field %@ of %@ which is of type %@ with "
|
|
//% @"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@@ -393,10 +410,16 @@ void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
|
|
//% [self class], field.name,
|
|
//% [self class], field.name,
|
|
//% TypeToString(GPBGetFieldDataType(field)));
|
|
//% TypeToString(GPBGetFieldDataType(field)));
|
|
//%#endif
|
|
//%#endif
|
|
|
|
+//% GPBSet##NAME##IvarWithFieldPrivate(self, field, value);
|
|
|
|
+//%}
|
|
|
|
+//%
|
|
|
|
+//%void GPBSet##NAME##IvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+//% NAME$S GPBFieldDescriptor *field,
|
|
|
|
+//% NAME$S TYPE value) {
|
|
//% GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
//% GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
|
|
+//% GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
//% if (oneof) {
|
|
//% if (oneof) {
|
|
-//% GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
|
|
-//% GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+//% GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
//% }
|
|
//% }
|
|
//%#if defined(DEBUG) && DEBUG
|
|
//%#if defined(DEBUG) && DEBUG
|
|
//% NSCAssert(self->messageStorage_ != NULL,
|
|
//% NSCAssert(self->messageStorage_ != NULL,
|
|
@@ -407,14 +430,13 @@ void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
|
|
//% if (self->messageStorage_ == NULL) return;
|
|
//% if (self->messageStorage_ == NULL) return;
|
|
//%#endif
|
|
//%#endif
|
|
//% uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
//% uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
-//% TYPE *typePtr = (TYPE *)&storage[field->description_->offset];
|
|
|
|
|
|
+//% TYPE *typePtr = (TYPE *)&storage[fieldDesc->offset];
|
|
//% *typePtr = value;
|
|
//% *typePtr = value;
|
|
-//% // proto2: any value counts as having been set; proto3, it
|
|
|
|
-//% // has to be a non zero value or be in a oneof.
|
|
|
|
-//% BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
|
|
|
|
-//% || (value != (TYPE)0)
|
|
|
|
-//% || (field->containingOneof_ != NULL));
|
|
|
|
-//% GPBSetHasIvarField(self, field, hasValue);
|
|
|
|
|
|
+//% // If the value is zero, then we only count the field as "set" if the field
|
|
|
|
+//% // shouldn't auto clear on zero.
|
|
|
|
+//% BOOL hasValue = ((value != (TYPE)0)
|
|
|
|
+//% || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0));
|
|
|
|
+//% GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue);
|
|
//% GPBBecomeVisibleToAutocreator(self);
|
|
//% GPBBecomeVisibleToAutocreator(self);
|
|
//%}
|
|
//%}
|
|
//%
|
|
//%
|
|
@@ -508,16 +530,14 @@ void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self,
|
|
static void GPBSetObjectIvarWithField(GPBMessage *self,
|
|
static void GPBSetObjectIvarWithField(GPBMessage *self,
|
|
GPBFieldDescriptor *field, id value) {
|
|
GPBFieldDescriptor *field, id value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetRetainedObjectIvarWithFieldInternal(self, field, [value retain],
|
|
|
|
- syntax);
|
|
|
|
|
|
+ GPBSetRetainedObjectIvarWithFieldPrivate(self, field, [value retain]);
|
|
}
|
|
}
|
|
|
|
|
|
static void GPBSetCopyObjectIvarWithField(GPBMessage *self,
|
|
static void GPBSetCopyObjectIvarWithField(GPBMessage *self,
|
|
GPBFieldDescriptor *field, id value);
|
|
GPBFieldDescriptor *field, id value);
|
|
|
|
|
|
// GPBSetCopyObjectIvarWithField is blocked from the analyzer because it flags
|
|
// GPBSetCopyObjectIvarWithField is blocked from the analyzer because it flags
|
|
-// a leak for the -copy even though GPBSetRetainedObjectIvarWithFieldInternal
|
|
|
|
|
|
+// a leak for the -copy even though GPBSetRetainedObjectIvarWithFieldPrivate
|
|
// is marked as consuming the value. Note: For some reason this doesn't happen
|
|
// is marked as consuming the value. Note: For some reason this doesn't happen
|
|
// with the -retain in GPBSetObjectIvarWithField.
|
|
// with the -retain in GPBSetObjectIvarWithField.
|
|
#if !defined(__clang_analyzer__)
|
|
#if !defined(__clang_analyzer__)
|
|
@@ -525,22 +545,18 @@ static void GPBSetCopyObjectIvarWithField(GPBMessage *self,
|
|
static void GPBSetCopyObjectIvarWithField(GPBMessage *self,
|
|
static void GPBSetCopyObjectIvarWithField(GPBMessage *self,
|
|
GPBFieldDescriptor *field, id value) {
|
|
GPBFieldDescriptor *field, id value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetRetainedObjectIvarWithFieldInternal(self, field, [value copy],
|
|
|
|
- syntax);
|
|
|
|
|
|
+ GPBSetRetainedObjectIvarWithFieldPrivate(self, field, [value copy]);
|
|
}
|
|
}
|
|
#endif // !defined(__clang_analyzer__)
|
|
#endif // !defined(__clang_analyzer__)
|
|
|
|
|
|
-void GPBSetObjectIvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field, id value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
- GPBSetRetainedObjectIvarWithFieldInternal(self, field, [value retain],
|
|
|
|
- syntax);
|
|
|
|
|
|
+void GPBSetObjectIvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field, id value) {
|
|
|
|
+ GPBSetRetainedObjectIvarWithFieldPrivate(self, field, [value retain]);
|
|
}
|
|
}
|
|
|
|
|
|
-void GPBSetRetainedObjectIvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- id value, GPBFileSyntax syntax) {
|
|
|
|
|
|
+void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ id value) {
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
@"%@: All messages should have storage (from init)",
|
|
@"%@: All messages should have storage (from init)",
|
|
[self class]);
|
|
[self class]);
|
|
@@ -579,39 +595,30 @@ void GPBSetRetainedObjectIvarWithFieldInternal(GPBMessage *self,
|
|
// valueData/valueMessage.
|
|
// valueData/valueMessage.
|
|
}
|
|
}
|
|
#endif // DEBUG
|
|
#endif // DEBUG
|
|
|
|
+ GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
if (!isMapOrArray) {
|
|
if (!isMapOrArray) {
|
|
// Non repeated/map can be in an oneof, clear any existing value from the
|
|
// Non repeated/map can be in an oneof, clear any existing value from the
|
|
// oneof.
|
|
// oneof.
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
if (oneof) {
|
|
if (oneof) {
|
|
- GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
|
|
- GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
}
|
|
}
|
|
// Clear "has" if they are being set to nil.
|
|
// Clear "has" if they are being set to nil.
|
|
BOOL setHasValue = (value != nil);
|
|
BOOL setHasValue = (value != nil);
|
|
- // Under proto3, Bytes & String fields get cleared by resetting them to
|
|
|
|
- // their default (empty) values, so if they are set to something of length
|
|
|
|
- // zero, they are being cleared.
|
|
|
|
- if ((syntax == GPBFileSyntaxProto3) && !fieldIsMessage &&
|
|
|
|
|
|
+ // If the field should clear on a "zero" value, then check if the string/data
|
|
|
|
+ // was zero length, and clear instead.
|
|
|
|
+ if (((fieldDesc->flags & GPBFieldClearHasIvarOnZero) != 0) &&
|
|
([value length] == 0)) {
|
|
([value length] == 0)) {
|
|
- // Except, if the field was in a oneof, then it still gets recorded as
|
|
|
|
- // having been set so the state of the oneof can be serialized back out.
|
|
|
|
- if (!oneof) {
|
|
|
|
- setHasValue = NO;
|
|
|
|
- }
|
|
|
|
- if (setHasValue) {
|
|
|
|
- NSCAssert(value != nil, @"Should never be setting has for nil");
|
|
|
|
- } else {
|
|
|
|
- // The value passed in was retained, it must be released since we
|
|
|
|
- // aren't saving anything in the field.
|
|
|
|
- [value release];
|
|
|
|
- value = nil;
|
|
|
|
- }
|
|
|
|
|
|
+ setHasValue = NO;
|
|
|
|
+ // The value passed in was retained, it must be released since we
|
|
|
|
+ // aren't saving anything in the field.
|
|
|
|
+ [value release];
|
|
|
|
+ value = nil;
|
|
}
|
|
}
|
|
- GPBSetHasIvarField(self, field, setHasValue);
|
|
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, setHasValue);
|
|
}
|
|
}
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
- id *typePtr = (id *)&storage[field->description_->offset];
|
|
|
|
|
|
+ id *typePtr = (id *)&storage[fieldDesc->offset];
|
|
|
|
|
|
id oldValue = *typePtr;
|
|
id oldValue = *typePtr;
|
|
|
|
|
|
@@ -678,23 +685,22 @@ id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self,
|
|
|
|
|
|
// Only exists for public api, no core code should use this.
|
|
// Only exists for public api, no core code should use this.
|
|
int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field) {
|
|
int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field) {
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- return GPBGetEnumIvarWithFieldInternal(self, field, syntax);
|
|
|
|
-}
|
|
|
|
|
|
+ #if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
|
|
+ NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeEnum,
|
|
|
|
+ @"Attempting to get value of type Enum from field %@ "
|
|
|
|
+ @"of %@ which is of type %@.",
|
|
|
|
+ [self class], field.name,
|
|
|
|
+ TypeToString(GPBGetFieldDataType(field)));
|
|
|
|
+ #endif
|
|
|
|
|
|
-int32_t GPBGetEnumIvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
-#if defined(DEBUG) && DEBUG
|
|
|
|
- NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeEnum,
|
|
|
|
- @"Attempting to get value of type Enum from field %@ "
|
|
|
|
- @"of %@ which is of type %@.",
|
|
|
|
- [self class], field.name,
|
|
|
|
- TypeToString(GPBGetFieldDataType(field)));
|
|
|
|
-#endif
|
|
|
|
int32_t result = GPBGetMessageInt32Field(self, field);
|
|
int32_t result = GPBGetMessageInt32Field(self, field);
|
|
// If this is presevering unknown enums, make sure the value is valid before
|
|
// If this is presevering unknown enums, make sure the value is valid before
|
|
// returning it.
|
|
// returning it.
|
|
|
|
+
|
|
|
|
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
if (GPBHasPreservingUnknownEnumSemantics(syntax) &&
|
|
if (GPBHasPreservingUnknownEnumSemantics(syntax) &&
|
|
![field isValidEnumValue:result]) {
|
|
![field isValidEnumValue:result]) {
|
|
result = kGPBUnrecognizedEnumeratorValue;
|
|
result = kGPBUnrecognizedEnumeratorValue;
|
|
@@ -705,27 +711,28 @@ int32_t GPBGetEnumIvarWithFieldInternal(GPBMessage *self,
|
|
// Only exists for public api, no core code should use this.
|
|
// Only exists for public api, no core code should use this.
|
|
void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field,
|
|
void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field,
|
|
int32_t value) {
|
|
int32_t value) {
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void GPBSetEnumIvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field, int32_t value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
-#if defined(DEBUG) && DEBUG
|
|
|
|
- NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeEnum,
|
|
|
|
- @"Attempting to set field %@ of %@ which is of type %@ with "
|
|
|
|
- @"value of type Enum.",
|
|
|
|
- [self class], field.name,
|
|
|
|
- TypeToString(GPBGetFieldDataType(field)));
|
|
|
|
-#endif
|
|
|
|
|
|
+ #if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
|
|
+ NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeEnum,
|
|
|
|
+ @"Attempting to set field %@ of %@ which is of type %@ with "
|
|
|
|
+ @"value of type Enum.",
|
|
|
|
+ [self class], field.name,
|
|
|
|
+ TypeToString(GPBGetFieldDataType(field)));
|
|
|
|
+ #endif
|
|
|
|
+ GPBSetEnumIvarWithFieldPrivate(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBSetEnumIvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field, int32_t value) {
|
|
// Don't allow in unknown values. Proto3 can use the Raw method.
|
|
// Don't allow in unknown values. Proto3 can use the Raw method.
|
|
if (![field isValidEnumValue:value]) {
|
|
if (![field isValidEnumValue:value]) {
|
|
[NSException raise:NSInvalidArgumentException
|
|
[NSException raise:NSInvalidArgumentException
|
|
format:@"%@.%@: Attempt to set an unknown enum value (%d)",
|
|
format:@"%@.%@: Attempt to set an unknown enum value (%d)",
|
|
[self class], field.name, value];
|
|
[self class], field.name, value];
|
|
}
|
|
}
|
|
- GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
|
|
+ GPBSetInt32IvarWithFieldPrivate(self, field, value);
|
|
}
|
|
}
|
|
|
|
|
|
// Only exists for public api, no core code should use this.
|
|
// Only exists for public api, no core code should use this.
|
|
@@ -738,13 +745,15 @@ int32_t GPBGetMessageRawEnumField(GPBMessage *self,
|
|
// Only exists for public api, no core code should use this.
|
|
// Only exists for public api, no core code should use this.
|
|
void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field,
|
|
void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field,
|
|
int32_t value) {
|
|
int32_t value) {
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
|
|
+ GPBSetInt32IvarWithFieldPrivate(self, field, value);
|
|
}
|
|
}
|
|
|
|
|
|
BOOL GPBGetMessageBoolField(GPBMessage *self,
|
|
BOOL GPBGetMessageBoolField(GPBMessage *self,
|
|
GPBFieldDescriptor *field) {
|
|
GPBFieldDescriptor *field) {
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field), GPBDataTypeBool),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field), GPBDataTypeBool),
|
|
@"Attempting to get value of type bool from field %@ "
|
|
@"Attempting to get value of type bool from field %@ "
|
|
@"of %@ which is of type %@.",
|
|
@"of %@ which is of type %@.",
|
|
@@ -768,25 +777,26 @@ void GPBSetMessageBoolField(GPBMessage *self,
|
|
GPBFieldDescriptor *field,
|
|
GPBFieldDescriptor *field,
|
|
BOOL value) {
|
|
BOOL value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetBoolIvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void GPBSetBoolIvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- BOOL value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
-#if defined(DEBUG) && DEBUG
|
|
|
|
- NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field), GPBDataTypeBool),
|
|
|
|
- @"Attempting to set field %@ of %@ which is of type %@ with "
|
|
|
|
- @"value of type bool.",
|
|
|
|
- [self class], field.name,
|
|
|
|
- TypeToString(GPBGetFieldDataType(field)));
|
|
|
|
-#endif
|
|
|
|
|
|
+ #if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
|
|
+ NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field), GPBDataTypeBool),
|
|
|
|
+ @"Attempting to set field %@ of %@ which is of type %@ with "
|
|
|
|
+ @"value of type bool.",
|
|
|
|
+ [self class], field.name,
|
|
|
|
+ TypeToString(GPBGetFieldDataType(field)));
|
|
|
|
+ #endif
|
|
|
|
+ GPBSetBoolIvarWithFieldPrivate(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBSetBoolIvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ BOOL value) {
|
|
GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
if (oneof) {
|
|
if (oneof) {
|
|
- GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
}
|
|
}
|
|
|
|
|
|
// Bools are stored in the has bits to avoid needing explicit space in the
|
|
// Bools are stored in the has bits to avoid needing explicit space in the
|
|
@@ -795,12 +805,11 @@ void GPBSetBoolIvarWithFieldInternal(GPBMessage *self,
|
|
// the offset is never negative)
|
|
// the offset is never negative)
|
|
GPBSetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number, value);
|
|
GPBSetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number, value);
|
|
|
|
|
|
- // proto2: any value counts as having been set; proto3, it
|
|
|
|
- // has to be a non zero value or be in a oneof.
|
|
|
|
- BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
|
|
|
|
- || (value != (BOOL)0)
|
|
|
|
- || (field->containingOneof_ != NULL));
|
|
|
|
- GPBSetHasIvarField(self, field, hasValue);
|
|
|
|
|
|
+ // If the value is zero, then we only count the field as "set" if the field
|
|
|
|
+ // shouldn't auto clear on zero.
|
|
|
|
+ BOOL hasValue = ((value != (BOOL)0)
|
|
|
|
+ || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0));
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -811,6 +820,9 @@ void GPBSetBoolIvarWithFieldInternal(GPBMessage *self,
|
|
int32_t GPBGetMessageInt32Field(GPBMessage *self,
|
|
int32_t GPBGetMessageInt32Field(GPBMessage *self,
|
|
GPBFieldDescriptor *field) {
|
|
GPBFieldDescriptor *field) {
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeInt32),
|
|
GPBDataTypeInt32),
|
|
@"Attempting to get value of int32_t from field %@ "
|
|
@"Attempting to get value of int32_t from field %@ "
|
|
@@ -832,15 +844,10 @@ void GPBSetMessageInt32Field(GPBMessage *self,
|
|
GPBFieldDescriptor *field,
|
|
GPBFieldDescriptor *field,
|
|
int32_t value) {
|
|
int32_t value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- int32_t value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeInt32),
|
|
GPBDataTypeInt32),
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@@ -848,10 +855,16 @@ void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
|
|
[self class], field.name,
|
|
[self class], field.name,
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
#endif
|
|
#endif
|
|
|
|
+ GPBSetInt32IvarWithFieldPrivate(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBSetInt32IvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ int32_t value) {
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
|
|
+ GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
if (oneof) {
|
|
if (oneof) {
|
|
- GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
|
|
- GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
}
|
|
}
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
@@ -862,14 +875,13 @@ void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
|
|
if (self->messageStorage_ == NULL) return;
|
|
if (self->messageStorage_ == NULL) return;
|
|
#endif
|
|
#endif
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
- int32_t *typePtr = (int32_t *)&storage[field->description_->offset];
|
|
|
|
|
|
+ int32_t *typePtr = (int32_t *)&storage[fieldDesc->offset];
|
|
*typePtr = value;
|
|
*typePtr = value;
|
|
- // proto2: any value counts as having been set; proto3, it
|
|
|
|
- // has to be a non zero value or be in a oneof.
|
|
|
|
- BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
|
|
|
|
- || (value != (int32_t)0)
|
|
|
|
- || (field->containingOneof_ != NULL));
|
|
|
|
- GPBSetHasIvarField(self, field, hasValue);
|
|
|
|
|
|
+ // If the value is zero, then we only count the field as "set" if the field
|
|
|
|
+ // shouldn't auto clear on zero.
|
|
|
|
+ BOOL hasValue = ((value != (int32_t)0)
|
|
|
|
+ || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0));
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -881,6 +893,9 @@ void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
|
|
uint32_t GPBGetMessageUInt32Field(GPBMessage *self,
|
|
uint32_t GPBGetMessageUInt32Field(GPBMessage *self,
|
|
GPBFieldDescriptor *field) {
|
|
GPBFieldDescriptor *field) {
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeUInt32),
|
|
GPBDataTypeUInt32),
|
|
@"Attempting to get value of uint32_t from field %@ "
|
|
@"Attempting to get value of uint32_t from field %@ "
|
|
@@ -902,15 +917,10 @@ void GPBSetMessageUInt32Field(GPBMessage *self,
|
|
GPBFieldDescriptor *field,
|
|
GPBFieldDescriptor *field,
|
|
uint32_t value) {
|
|
uint32_t value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetUInt32IvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- uint32_t value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeUInt32),
|
|
GPBDataTypeUInt32),
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@@ -918,10 +928,16 @@ void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
|
|
[self class], field.name,
|
|
[self class], field.name,
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
#endif
|
|
#endif
|
|
|
|
+ GPBSetUInt32IvarWithFieldPrivate(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBSetUInt32IvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ uint32_t value) {
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
|
|
+ GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
if (oneof) {
|
|
if (oneof) {
|
|
- GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
|
|
- GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
}
|
|
}
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
@@ -932,14 +948,13 @@ void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
|
|
if (self->messageStorage_ == NULL) return;
|
|
if (self->messageStorage_ == NULL) return;
|
|
#endif
|
|
#endif
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
- uint32_t *typePtr = (uint32_t *)&storage[field->description_->offset];
|
|
|
|
|
|
+ uint32_t *typePtr = (uint32_t *)&storage[fieldDesc->offset];
|
|
*typePtr = value;
|
|
*typePtr = value;
|
|
- // proto2: any value counts as having been set; proto3, it
|
|
|
|
- // has to be a non zero value or be in a oneof.
|
|
|
|
- BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
|
|
|
|
- || (value != (uint32_t)0)
|
|
|
|
- || (field->containingOneof_ != NULL));
|
|
|
|
- GPBSetHasIvarField(self, field, hasValue);
|
|
|
|
|
|
+ // If the value is zero, then we only count the field as "set" if the field
|
|
|
|
+ // shouldn't auto clear on zero.
|
|
|
|
+ BOOL hasValue = ((value != (uint32_t)0)
|
|
|
|
+ || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0));
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -951,6 +966,9 @@ void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
|
|
int64_t GPBGetMessageInt64Field(GPBMessage *self,
|
|
int64_t GPBGetMessageInt64Field(GPBMessage *self,
|
|
GPBFieldDescriptor *field) {
|
|
GPBFieldDescriptor *field) {
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeInt64),
|
|
GPBDataTypeInt64),
|
|
@"Attempting to get value of int64_t from field %@ "
|
|
@"Attempting to get value of int64_t from field %@ "
|
|
@@ -972,15 +990,10 @@ void GPBSetMessageInt64Field(GPBMessage *self,
|
|
GPBFieldDescriptor *field,
|
|
GPBFieldDescriptor *field,
|
|
int64_t value) {
|
|
int64_t value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetInt64IvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- int64_t value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeInt64),
|
|
GPBDataTypeInt64),
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@@ -988,10 +1001,16 @@ void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
|
|
[self class], field.name,
|
|
[self class], field.name,
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
#endif
|
|
#endif
|
|
|
|
+ GPBSetInt64IvarWithFieldPrivate(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBSetInt64IvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ int64_t value) {
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
|
|
+ GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
if (oneof) {
|
|
if (oneof) {
|
|
- GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
|
|
- GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
}
|
|
}
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
@@ -1002,14 +1021,13 @@ void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
|
|
if (self->messageStorage_ == NULL) return;
|
|
if (self->messageStorage_ == NULL) return;
|
|
#endif
|
|
#endif
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
- int64_t *typePtr = (int64_t *)&storage[field->description_->offset];
|
|
|
|
|
|
+ int64_t *typePtr = (int64_t *)&storage[fieldDesc->offset];
|
|
*typePtr = value;
|
|
*typePtr = value;
|
|
- // proto2: any value counts as having been set; proto3, it
|
|
|
|
- // has to be a non zero value or be in a oneof.
|
|
|
|
- BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
|
|
|
|
- || (value != (int64_t)0)
|
|
|
|
- || (field->containingOneof_ != NULL));
|
|
|
|
- GPBSetHasIvarField(self, field, hasValue);
|
|
|
|
|
|
+ // If the value is zero, then we only count the field as "set" if the field
|
|
|
|
+ // shouldn't auto clear on zero.
|
|
|
|
+ BOOL hasValue = ((value != (int64_t)0)
|
|
|
|
+ || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0));
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1021,6 +1039,9 @@ void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
|
|
uint64_t GPBGetMessageUInt64Field(GPBMessage *self,
|
|
uint64_t GPBGetMessageUInt64Field(GPBMessage *self,
|
|
GPBFieldDescriptor *field) {
|
|
GPBFieldDescriptor *field) {
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeUInt64),
|
|
GPBDataTypeUInt64),
|
|
@"Attempting to get value of uint64_t from field %@ "
|
|
@"Attempting to get value of uint64_t from field %@ "
|
|
@@ -1042,15 +1063,10 @@ void GPBSetMessageUInt64Field(GPBMessage *self,
|
|
GPBFieldDescriptor *field,
|
|
GPBFieldDescriptor *field,
|
|
uint64_t value) {
|
|
uint64_t value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetUInt64IvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- uint64_t value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeUInt64),
|
|
GPBDataTypeUInt64),
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@@ -1058,10 +1074,16 @@ void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
|
|
[self class], field.name,
|
|
[self class], field.name,
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
#endif
|
|
#endif
|
|
|
|
+ GPBSetUInt64IvarWithFieldPrivate(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBSetUInt64IvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ uint64_t value) {
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
|
|
+ GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
if (oneof) {
|
|
if (oneof) {
|
|
- GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
|
|
- GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
}
|
|
}
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
@@ -1072,14 +1094,13 @@ void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
|
|
if (self->messageStorage_ == NULL) return;
|
|
if (self->messageStorage_ == NULL) return;
|
|
#endif
|
|
#endif
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
- uint64_t *typePtr = (uint64_t *)&storage[field->description_->offset];
|
|
|
|
|
|
+ uint64_t *typePtr = (uint64_t *)&storage[fieldDesc->offset];
|
|
*typePtr = value;
|
|
*typePtr = value;
|
|
- // proto2: any value counts as having been set; proto3, it
|
|
|
|
- // has to be a non zero value or be in a oneof.
|
|
|
|
- BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
|
|
|
|
- || (value != (uint64_t)0)
|
|
|
|
- || (field->containingOneof_ != NULL));
|
|
|
|
- GPBSetHasIvarField(self, field, hasValue);
|
|
|
|
|
|
+ // If the value is zero, then we only count the field as "set" if the field
|
|
|
|
+ // shouldn't auto clear on zero.
|
|
|
|
+ BOOL hasValue = ((value != (uint64_t)0)
|
|
|
|
+ || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0));
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1091,6 +1112,9 @@ void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
|
|
float GPBGetMessageFloatField(GPBMessage *self,
|
|
float GPBGetMessageFloatField(GPBMessage *self,
|
|
GPBFieldDescriptor *field) {
|
|
GPBFieldDescriptor *field) {
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeFloat),
|
|
GPBDataTypeFloat),
|
|
@"Attempting to get value of float from field %@ "
|
|
@"Attempting to get value of float from field %@ "
|
|
@@ -1112,15 +1136,10 @@ void GPBSetMessageFloatField(GPBMessage *self,
|
|
GPBFieldDescriptor *field,
|
|
GPBFieldDescriptor *field,
|
|
float value) {
|
|
float value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetFloatIvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- float value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeFloat),
|
|
GPBDataTypeFloat),
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@@ -1128,10 +1147,16 @@ void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
|
|
[self class], field.name,
|
|
[self class], field.name,
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
#endif
|
|
#endif
|
|
|
|
+ GPBSetFloatIvarWithFieldPrivate(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBSetFloatIvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ float value) {
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
|
|
+ GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
if (oneof) {
|
|
if (oneof) {
|
|
- GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
|
|
- GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
}
|
|
}
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
@@ -1142,14 +1167,13 @@ void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
|
|
if (self->messageStorage_ == NULL) return;
|
|
if (self->messageStorage_ == NULL) return;
|
|
#endif
|
|
#endif
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
- float *typePtr = (float *)&storage[field->description_->offset];
|
|
|
|
|
|
+ float *typePtr = (float *)&storage[fieldDesc->offset];
|
|
*typePtr = value;
|
|
*typePtr = value;
|
|
- // proto2: any value counts as having been set; proto3, it
|
|
|
|
- // has to be a non zero value or be in a oneof.
|
|
|
|
- BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
|
|
|
|
- || (value != (float)0)
|
|
|
|
- || (field->containingOneof_ != NULL));
|
|
|
|
- GPBSetHasIvarField(self, field, hasValue);
|
|
|
|
|
|
+ // If the value is zero, then we only count the field as "set" if the field
|
|
|
|
+ // shouldn't auto clear on zero.
|
|
|
|
+ BOOL hasValue = ((value != (float)0)
|
|
|
|
+ || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0));
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1161,6 +1185,9 @@ void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
|
|
double GPBGetMessageDoubleField(GPBMessage *self,
|
|
double GPBGetMessageDoubleField(GPBMessage *self,
|
|
GPBFieldDescriptor *field) {
|
|
GPBFieldDescriptor *field) {
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeDouble),
|
|
GPBDataTypeDouble),
|
|
@"Attempting to get value of double from field %@ "
|
|
@"Attempting to get value of double from field %@ "
|
|
@@ -1182,15 +1209,10 @@ void GPBSetMessageDoubleField(GPBMessage *self,
|
|
GPBFieldDescriptor *field,
|
|
GPBFieldDescriptor *field,
|
|
double value) {
|
|
double value) {
|
|
if (self == nil || field == nil) return;
|
|
if (self == nil || field == nil) return;
|
|
- GPBFileSyntax syntax = [self descriptor].file.syntax;
|
|
|
|
- GPBSetDoubleIvarWithFieldInternal(self, field, value, syntax);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
|
|
|
|
- GPBFieldDescriptor *field,
|
|
|
|
- double value,
|
|
|
|
- GPBFileSyntax syntax) {
|
|
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] fieldWithNumber:field.number] == field,
|
|
|
|
+ @"FieldDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ field.name, [self class]);
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field),
|
|
GPBDataTypeDouble),
|
|
GPBDataTypeDouble),
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@"Attempting to set field %@ of %@ which is of type %@ with "
|
|
@@ -1198,10 +1220,16 @@ void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
|
|
[self class], field.name,
|
|
[self class], field.name,
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
TypeToString(GPBGetFieldDataType(field)));
|
|
#endif
|
|
#endif
|
|
|
|
+ GPBSetDoubleIvarWithFieldPrivate(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBSetDoubleIvarWithFieldPrivate(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ double value) {
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
GPBOneofDescriptor *oneof = field->containingOneof_;
|
|
|
|
+ GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
if (oneof) {
|
|
if (oneof) {
|
|
- GPBMessageFieldDescription *fieldDesc = field->description_;
|
|
|
|
- GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
|
|
}
|
|
}
|
|
#if defined(DEBUG) && DEBUG
|
|
#if defined(DEBUG) && DEBUG
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
NSCAssert(self->messageStorage_ != NULL,
|
|
@@ -1212,14 +1240,13 @@ void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
|
|
if (self->messageStorage_ == NULL) return;
|
|
if (self->messageStorage_ == NULL) return;
|
|
#endif
|
|
#endif
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
uint8_t *storage = (uint8_t *)self->messageStorage_;
|
|
- double *typePtr = (double *)&storage[field->description_->offset];
|
|
|
|
|
|
+ double *typePtr = (double *)&storage[fieldDesc->offset];
|
|
*typePtr = value;
|
|
*typePtr = value;
|
|
- // proto2: any value counts as having been set; proto3, it
|
|
|
|
- // has to be a non zero value or be in a oneof.
|
|
|
|
- BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
|
|
|
|
- || (value != (double)0)
|
|
|
|
- || (field->containingOneof_ != NULL));
|
|
|
|
- GPBSetHasIvarField(self, field, hasValue);
|
|
|
|
|
|
+ // If the value is zero, then we only count the field as "set" if the field
|
|
|
|
+ // shouldn't auto clear on zero.
|
|
|
|
+ BOOL hasValue = ((value != (double)0)
|
|
|
|
+ || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0));
|
|
|
|
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
GPBBecomeVisibleToAutocreator(self);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2212,8 +2239,36 @@ NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key,
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#pragma mark Legacy methods old generated code calls
|
|
|
|
+
|
|
|
|
+// Shim from the older generated code into the runtime.
|
|
|
|
+void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
|
|
|
|
+ GPBFieldDescriptor *field,
|
|
|
|
+ int32_t value,
|
|
|
|
+ GPBFileSyntax syntax) {
|
|
|
|
+#pragma unused(syntax)
|
|
|
|
+ GPBSetMessageInt32Field(self, field, value);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
|
|
|
|
+ int32_t oneofHasIndex, uint32_t fieldNumberNotToClear) {
|
|
|
|
+#pragma unused(fieldNumberNotToClear)
|
|
|
|
+ #if defined(DEBUG) && DEBUG
|
|
|
|
+ NSCAssert([[self descriptor] oneofWithName:oneof.name] == oneof,
|
|
|
|
+ @"OneofDescriptor %@ doesn't appear to be for %@ messages.",
|
|
|
|
+ oneof.name, [self class]);
|
|
|
|
+ GPBFieldDescriptor *firstField = oneof->fields_[0];
|
|
|
|
+ NSCAssert(firstField->description_->hasIndex == oneofHasIndex,
|
|
|
|
+ @"Internal error, oneofHasIndex (%d) doesn't match (%d).",
|
|
|
|
+ firstField->description_->hasIndex, oneofHasIndex);
|
|
|
|
+ #endif
|
|
|
|
+ GPBMaybeClearOneofPrivate(self, oneof, oneofHasIndex, 0);
|
|
|
|
+}
|
|
|
|
+
|
|
#pragma clang diagnostic pop
|
|
#pragma clang diagnostic pop
|
|
|
|
|
|
|
|
+#pragma mark Misc Helpers
|
|
|
|
+
|
|
BOOL GPBClassHasSel(Class aClass, SEL sel) {
|
|
BOOL GPBClassHasSel(Class aClass, SEL sel) {
|
|
// NOTE: We have to use class_copyMethodList, all other runtime method
|
|
// NOTE: We have to use class_copyMethodList, all other runtime method
|
|
// lookups actually also resolve the method implementation and this
|
|
// lookups actually also resolve the method implementation and this
|