aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec/GPBMessage.m
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2016-06-27 20:45:16 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-06-27 20:46:26 -0400
commitfc4c6171999243695166747108cf7d65e34bf4c0 (patch)
tree7360762dca9acb20660e0113659d382fe295996b /objectivec/GPBMessage.m
parent2bcd43afe4b649c95d932daf31b0b83948f7cf7c (diff)
Fix GPBGetMessage{Repeated,Map}Field()
- Correct impl by using helpers the message wiring does. - Add unittests. Fixes https://github.com/google/protobuf/issues/1716
Diffstat (limited to 'objectivec/GPBMessage.m')
-rw-r--r--objectivec/GPBMessage.m30
1 files changed, 30 insertions, 0 deletions
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m
index 919fb931..7ab184c1 100644
--- a/objectivec/GPBMessage.m
+++ b/objectivec/GPBMessage.m
@@ -3199,4 +3199,34 @@ static void ResolveIvarSet(GPBFieldDescriptor *field,
@end
+#pragma mark - Messages from GPBUtilities.h but defined here for access to helpers.
+
+// Only exists for public api, no core code should use this.
+id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeRepeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a repeated field.",
+ [self class], field.name];
+ }
+#endif
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+ return GetOrCreateArrayIvarWithField(self, field, syntax);
+}
+
+// Only exists for public api, no core code should use this.
+id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeMap) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a map<> field.",
+ [self class], field.name];
+ }
+#endif
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+ return GetOrCreateMapIvarWithField(self, field, syntax);
+}
+
#pragma clang diagnostic pop