aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient/private
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-04-24 14:16:54 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-04-24 14:16:54 -0700
commit3d13eb056c07f125f23caecbb785d4920be4516a (patch)
treef88ee784c45ff88370a6a4835a1a3069d5cabb70 /src/objective-c/GRPCClient/private
parent69927d65c3b9f3f65ff34b27140b3d2ad2d1c1ec (diff)
Fixed grpc_getMetadataArray
Diffstat (limited to 'src/objective-c/GRPCClient/private')
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.m3
-rw-r--r--src/objective-c/GRPCClient/private/NSDictionary+GRPC.h2
-rw-r--r--src/objective-c/GRPCClient/private/NSDictionary+GRPC.m27
3 files changed, 16 insertions, 16 deletions
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