diff options
author | David G. Quintas <dgq@google.com> | 2017-01-23 12:08:46 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-23 12:08:46 -0800 |
commit | f2c5c1e541a3c42fd418063ec24bb9e591b3ad40 (patch) | |
tree | a93b1c9939dccef7173b56ee73a7aadd9e1e8ccb /src/objective-c | |
parent | 6e407b77627a538c4a9dda96fcf00438dcb76041 (diff) | |
parent | 5e01e2ac977655aa074faf7fde0a74298f5e4c55 (diff) |
Merge pull request #9428 from grpc/revert-8842-metadata_filter
Revert "Metadata handling rewrite"
Diffstat (limited to 'src/objective-c')
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCChannel.m | 2 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCWrappedCall.m | 19 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/NSDictionary+GRPC.m | 20 |
3 files changed, 18 insertions, 23 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index c533c5ae71..2397c929f7 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -200,7 +200,7 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { return grpc_channel_create_call(_unmanagedChannel, NULL, GRPC_PROPAGATE_DEFAULTS, queue.unmanagedQueue, - grpc_slice_from_copied_string(path.UTF8String), + path.UTF8String, NULL, // Passing NULL for host gpr_inf_future(GPR_CLOCK_REALTIME), NULL); } diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m index 43c564552b..38fcae0299 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -194,7 +194,7 @@ @implementation GRPCOpRecvStatus{ grpc_status_code _statusCode; - grpc_slice _details; + char *_details; size_t _detailsCapacity; grpc_metadata_array _trailers; } @@ -208,6 +208,7 @@ _op.op = GRPC_OP_RECV_STATUS_ON_CLIENT; _op.data.recv_status_on_client.status = &_statusCode; _op.data.recv_status_on_client.status_details = &_details; + _op.data.recv_status_on_client.status_details_capacity = &_detailsCapacity; grpc_metadata_array_init(&_trailers); _op.data.recv_status_on_client.trailing_metadata = &_trailers; if (handler) { @@ -215,15 +216,11 @@ __weak typeof(self) weakSelf = self; _handler = ^{ __strong typeof(self) strongSelf = weakSelf; - if (strongSelf) { - char *details = grpc_slice_to_c_string(strongSelf->_details); - NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode - details:details]; - NSDictionary *trailers = [NSDictionary - grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; - handler(error, trailers); - gpr_free(details); - } + NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode + details:strongSelf->_details]; + NSDictionary *trailers = [NSDictionary + grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; + handler(error, trailers); }; } } @@ -232,7 +229,7 @@ - (void)dealloc { grpc_metadata_array_destroy(&_trailers); - grpc_slice_unref(_details); + gpr_free(_details); } @end diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m index feb2bb5ed8..7477da7619 100644 --- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m @@ -47,12 +47,12 @@ @implementation NSData (GRPCMetadata) + (instancetype)grpc_dataFromMetadataValue:(grpc_metadata *)metadata { // TODO(jcanizales): Should we use a non-copy constructor? - return [self dataWithBytes:GRPC_SLICE_START_PTR(metadata->value) - length:GRPC_SLICE_LENGTH(metadata->value)]; + return [self dataWithBytes:metadata->value length:metadata->value_length]; } - (void)grpc_initMetadata:(grpc_metadata *)metadata { - metadata->value = grpc_slice_from_copied_buffer(self.bytes, self.length); + metadata->value = self.bytes; + metadata->value_length = self.length; } @end @@ -67,14 +67,15 @@ @implementation NSString (GRPCMetadata) + (instancetype)grpc_stringFromMetadataValue:(grpc_metadata *)metadata { - return [[self alloc] initWithBytes:GRPC_SLICE_START_PTR(metadata->value) - length:GRPC_SLICE_LENGTH(metadata->value) + return [[self alloc] initWithBytes:metadata->value + length:metadata->value_length encoding:NSASCIIStringEncoding]; } // Precondition: This object contains only ASCII characters. - (void)grpc_initMetadata:(grpc_metadata *)metadata { - metadata->value = grpc_slice_from_copied_string(self.UTF8String); + metadata->value = self.UTF8String; + metadata->value_length = self.length; } @end @@ -88,10 +89,7 @@ + (instancetype)grpc_dictionaryFromMetadata:(grpc_metadata *)entries count:(size_t)count { NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithCapacity:count]; for (grpc_metadata *entry = entries; entry < entries + count; entry++) { - char *key = grpc_slice_to_c_string(entry->key); - NSString *name = [NSString stringWithCString:key - encoding:NSASCIIStringEncoding]; - gpr_free(key); + NSString *name = [NSString stringWithCString:entry->key encoding:NSASCIIStringEncoding]; if (!name || metadata[name]) { // Log if name is nil? continue; @@ -114,7 +112,7 @@ grpc_metadata *current = metadata; for (NSString* key in self) { id value = self[key]; - current->key = grpc_slice_from_copied_string(key.UTF8String); + current->key = key.UTF8String; if ([value respondsToSelector:@selector(grpc_initMetadata:)]) { [value grpc_initMetadata:current]; } else { |