diff options
Diffstat (limited to 'src/objective-c/GRPCClient/private/NSData+GRPC.m')
-rw-r--r-- | src/objective-c/GRPCClient/private/NSData+GRPC.m | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/objective-c/GRPCClient/private/NSData+GRPC.m b/src/objective-c/GRPCClient/private/NSData+GRPC.m index 6ea4ce979e..e6a6c3c605 100644 --- a/src/objective-c/GRPCClient/private/NSData+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSData+GRPC.m @@ -34,25 +34,28 @@ #import "NSData+GRPC.h" #include <grpc/byte_buffer.h> +#include <grpc/byte_buffer_reader.h> #include <string.h> // TODO(jcanizales): Move these two incantations to the C library. static void CopyByteBufferToCharArray(grpc_byte_buffer *buffer, char *array) { size_t offset = 0; - grpc_byte_buffer_reader *reader = grpc_byte_buffer_reader_create(buffer); + grpc_byte_buffer_reader reader; + grpc_byte_buffer_reader_init(&reader, buffer); gpr_slice next; - while (grpc_byte_buffer_reader_next(reader, &next) != 0){ - memcpy(array + offset, GPR_SLICE_START_PTR(next), (size_t) GPR_SLICE_LENGTH(next)); + while (grpc_byte_buffer_reader_next(&reader, &next) != 0){ + memcpy(array + offset, GPR_SLICE_START_PTR(next), + (size_t)GPR_SLICE_LENGTH(next)); offset += GPR_SLICE_LENGTH(next); gpr_slice_unref(next); } - grpc_byte_buffer_reader_destroy(reader); } -static grpc_byte_buffer *CopyCharArrayToNewByteBuffer(const char *array, size_t length) { +static grpc_byte_buffer *CopyCharArrayToNewByteBuffer(const char *array, + size_t length) { gpr_slice slice = gpr_slice_from_copied_buffer(array, length); - grpc_byte_buffer *buffer = grpc_byte_buffer_create(&slice, 1); + grpc_byte_buffer *buffer = grpc_raw_byte_buffer_create(&slice, 1); gpr_slice_unref(slice); return buffer; } @@ -82,7 +85,7 @@ static grpc_byte_buffer *CopyCharArrayToNewByteBuffer(const char *array, size_t // The following implementation is thus not optimal, sometimes requiring two // copies (one by self.bytes and another by gpr_slice_from_copied_buffer). // If it turns out to be an issue, we can use enumerateByteRangesUsingblock: - // to create an array of gpr_slice objects to pass to grpc_byte_buffer_create. + // to create an array of gpr_slice objects to pass to grpc_raw_byte_buffer_create. // That would make it do exactly one copy, always. return CopyCharArrayToNewByteBuffer((const char *)self.bytes, (size_t)self.length); } |