From 3d13eb056c07f125f23caecbb785d4920be4516a Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 24 Apr 2015 14:16:54 -0700 Subject: Fixed grpc_getMetadataArray --- .../GRPCClient/private/GRPCWrappedCall.m | 3 ++- .../GRPCClient/private/NSDictionary+GRPC.h | 2 +- .../GRPCClient/private/NSDictionary+GRPC.m | 27 +++++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/objective-c/GRPCClient/private') diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m index a2acb4b708..8c8e30986f 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -94,7 +94,8 @@ switch ([key intValue]) { case GRPC_OP_SEND_INITIAL_METADATA: // TODO(jcanizales): Name the type of current->data.send_initial_metadata in the C library so a pointer to it can be returned from methods. - current->data.send_initial_metadata.count = [operations[key] grpc_toMetadataArray:&send_metadata]; + current->data.send_initial_metadata.count = [operations[key] count]; + [operations[key] grpc_getMetadataArray:&send_metadata]; current->data.send_initial_metadata.metadata = send_metadata; opBlock = ^{ gpr_free(send_metadata); diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.h b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.h index f6aeed35c0..fec2adb212 100644 --- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.h +++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.h @@ -36,5 +36,5 @@ @interface NSDictionary (GRPC) + (instancetype)grpc_dictionaryFromMetadata:(struct grpc_metadata *)entries count:(size_t)count; -- (size_t)grpc_toMetadataArray:(grpc_metadata **)metadata; +- (void)grpc_getMetadataArray:(grpc_metadata **)metadata; @end diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m index 1df06c167f..1b8e6a3a17 100644 --- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m @@ -55,23 +55,22 @@ return metadata; } -- (size_t)grpc_toMetadataArray:(grpc_metadata **)metadata { - size_t count = 0; - size_t capacity = 0; +- (void)grpc_getMetadataArray:(grpc_metadata **)metadata { + *metadata = gpr_malloc([self count] * sizeof(grpc_metadata)); + int i = 0; for (id key in self) { - capacity += [self[key] count]; - } - *metadata = gpr_malloc(capacity * sizeof(grpc_metadata)); - for (id key in self) { - id value_array = self[key]; - for (id value in value_array) { - grpc_metadata *current = &(*metadata)[count]; - current->key = [key UTF8String]; + id value = self[key]; + grpc_metadata *current = &(*metadata)[i]; + current->key = [key UTF8String]; + if ([value isKindOfClass:[NSData class]]) { + current->value = [value bytes]; + } else if ([value isKindOfClass:[NSString class]]) { current->value = [value UTF8String]; - current->value_length = [value length]; - count += 1; + } else { + [NSException raise:NSInvalidArgumentException format:@"Metadata values must be NSString or NSData."]; } + current->value = [value UTF8String]; + i += 1; } - return count; } @end -- cgit v1.2.3