diff options
author | thinkerou <thinkerou@gmail.com> | 2016-06-03 18:42:48 +0800 |
---|---|---|
committer | thinkerou <thinkerou@gmail.com> | 2016-06-17 10:55:01 +0800 |
commit | f09ab0c5add9289d40429df63b9f85b6545e9558 (patch) | |
tree | 5aa1df0214e6f6a7db0bac211edb333e8085765d /src/php | |
parent | fa9b7c1bc6488be17d18007f45c57dac39ea5b79 (diff) |
Make PHP work correctly when receiving a compressed message
Diffstat (limited to 'src/php')
-rw-r--r-- | src/php/ext/grpc/byte_buffer.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/php/ext/grpc/byte_buffer.c b/src/php/ext/grpc/byte_buffer.c index 7a726de5db..92ec39952c 100644 --- a/src/php/ext/grpc/byte_buffer.c +++ b/src/php/ext/grpc/byte_buffer.c @@ -63,17 +63,15 @@ void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string, *out_length = 0; return; } - size_t length = grpc_byte_buffer_length(buffer); - char *string = ecalloc(length + 1, sizeof(char)); - size_t offset = 0; + 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(string + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next)); - offset += GPR_SLICE_LENGTH(next); - gpr_slice_unref(next); - } + gpr_slice slice = grpc_byte_buffer_reader_readall(&reader); + size_t length = GPR_SLICE_LENGTH(slice); + char *string = ecalloc(length + 1, sizeof(char)); + memcpy(string, GPR_SLICE_START_PTR(slice), length); + gpr_slice_unref(slice); + *out_string = string; *out_length = length; } |