From fc4c6171999243695166747108cf7d65e34bf4c0 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 27 Jun 2016 20:45:16 -0400 Subject: Fix GPBGetMessage{Repeated,Map}Field() - Correct impl by using helpers the message wiring does. - Add unittests. Fixes https://github.com/google/protobuf/issues/1716 --- objectivec/GPBMessage.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'objectivec/GPBMessage.m') 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 -- cgit v1.2.3