aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/objective-c/GRPCClient/private/NSDictionary+GRPC.m')
-rw-r--r--src/objective-c/GRPCClient/private/NSDictionary+GRPC.m22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m
index e59685e4a8..c350f32f2a 100644
--- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m
+++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m
@@ -33,7 +33,7 @@
#import "NSDictionary+GRPC.h"
-#include <grpc.h>
+#include <grpc/support/alloc.h>
@implementation NSDictionary (GRPC)
+ (instancetype)grpc_dictionaryFromMetadata:(grpc_metadata *)entries count:(size_t)count {
@@ -53,4 +53,24 @@
}
return metadata;
}
+
+- (grpc_metadata *)grpc_metadataArray {
+ grpc_metadata *metadata = gpr_malloc([self count] * sizeof(grpc_metadata));
+ int i = 0;
+ for (id key in self) {
+ 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];
+ } else {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Metadata values must be NSString or NSData."];
+ }
+ i += 1;
+ }
+ return metadata;
+}
@end