diff options
Diffstat (limited to 'src/objective-c/GRPCClient')
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCChannel.m | 2 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCWrappedCall.m | 27 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/NSDictionary+GRPC.m | 20 |
3 files changed, 22 insertions, 27 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..45d0aae203 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -105,14 +105,14 @@ } if (self = [super init]) { _op.op = GRPC_OP_SEND_MESSAGE; - _op.data.send_message = message.grpc_byteBuffer; + _op.data.send_message.send_message = message.grpc_byteBuffer; _handler = handler; } return self; } - (void)dealloc { - grpc_byte_buffer_destroy(_op.data.send_message); + grpc_byte_buffer_destroy(_op.data.send_message.send_message); } @end @@ -145,7 +145,7 @@ if (self = [super init]) { _op.op = GRPC_OP_RECV_INITIAL_METADATA; grpc_metadata_array_init(&_headers); - _op.data.recv_initial_metadata = &_headers; + _op.data.recv_initial_metadata.recv_initial_metadata = &_headers; if (handler) { // Prevent reference cycle with _handler __weak typeof(self) weakSelf = self; @@ -177,7 +177,7 @@ - (instancetype)initWithHandler:(void (^)(grpc_byte_buffer *))handler { if (self = [super init]) { _op.op = GRPC_OP_RECV_MESSAGE; - _op.data.recv_message = &_receivedMessage; + _op.data.recv_message.recv_message = &_receivedMessage; if (handler) { // Prevent reference cycle with _handler __weak typeof(self) weakSelf = self; @@ -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 { |