diff options
author | David Garcia Quintas <dgq@google.com> | 2015-10-30 17:01:05 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2015-10-30 17:24:41 -0700 |
commit | 6eb3925a70c70e64e4c4d8577e40841473f19423 (patch) | |
tree | b7bdb62245a59e3c5fa57180090dc9f449b33db5 /src/core | |
parent | 89ea0c78151b5bdc4c9236ae7100a7b97b32e499 (diff) |
Added grpc_byte_buffer_reader_readall
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/surface/byte_buffer_reader.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/surface/byte_buffer_reader.c b/src/core/surface/byte_buffer_reader.c index 283db83833..9f830df68c 100644 --- a/src/core/surface/byte_buffer_reader.c +++ b/src/core/surface/byte_buffer_reader.c @@ -31,6 +31,7 @@ * */ +#include <string.h> #include <grpc/byte_buffer_reader.h> #include <grpc/compression.h> @@ -103,3 +104,21 @@ int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader, } return 0; } + +gpr_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader) { + gpr_slice in_slice; + size_t bytes_read = 0; + const size_t input_size = grpc_byte_buffer_length(reader->buffer_out); + gpr_slice out_slice = gpr_slice_malloc(input_size); + gpr_uint8 *const outbuf = GPR_SLICE_START_PTR(out_slice); /* just an alias */ + + while (grpc_byte_buffer_reader_next(reader, &in_slice) != 0) { + const size_t slice_length = GPR_SLICE_LENGTH(in_slice); + memcpy(&(outbuf[bytes_read]), GPR_SLICE_START_PTR(in_slice), slice_length); + bytes_read += slice_length; + gpr_slice_unref(in_slice); + GPR_ASSERT(bytes_read <= input_size); + } + return out_slice; +} + |