Fixed grpc_getMetadataArray

pull/1363/head
murgatroid99 10 years ago
parent 69927d65c3
commit 3d13eb056c
  1. 3
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  2. 2
      src/objective-c/GRPCClient/private/NSDictionary+GRPC.h
  3. 27
      src/objective-c/GRPCClient/private/NSDictionary+GRPC.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);

@ -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

@ -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

Loading…
Cancel
Save