diff options
author | Craig Tiller <ctiller@google.com> | 2015-11-04 10:51:51 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-11-04 10:51:51 -0800 |
commit | 6c4ec787e6c5dac2313338834aa9a909900a58f6 (patch) | |
tree | 943f465c82a81edc176574d4a0366834fbfbd1d2 /src | |
parent | 52541439e41d6d35fe89d8dfad94c1913f44c382 (diff) | |
parent | 6eb3925a70c70e64e4c4d8577e40841473f19423 (diff) |
Merge pull request #4013 from dgquintas/bb_readall
Added grpc_byte_buffer_reader_readall
Diffstat (limited to 'src')
-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; +} + |