Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Nicolas "Pixel" Noble | 1ff52d5 | 2015-03-01 05:24:36 +0100 | [diff] [blame] | 34 | #ifndef GRPC_BYTE_BUFFER_H |
| 35 | #define GRPC_BYTE_BUFFER_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
David Garcia Quintas | 3b31fdf | 2016-07-27 18:17:12 -0700 | [diff] [blame] | 37 | #include <grpc/impl/codegen/grpc_types.h> |
Craig Tiller | b37d53e | 2016-10-26 16:16:35 -0700 | [diff] [blame] | 38 | #include <grpc/slice_buffer.h> |
David Garcia Quintas | 3b31fdf | 2016-07-27 18:17:12 -0700 | [diff] [blame] | 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
| 44 | /** Returns a RAW byte buffer instance over the given slices (up to \a nslices). |
| 45 | * |
| 46 | * Increases the reference count for all \a slices processed. The user is |
| 47 | * responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 48 | GRPCAPI grpc_byte_buffer *grpc_raw_byte_buffer_create(grpc_slice *slices, |
David Garcia Quintas | 3b31fdf | 2016-07-27 18:17:12 -0700 | [diff] [blame] | 49 | size_t nslices); |
| 50 | |
| 51 | /** Returns a *compressed* RAW byte buffer instance over the given slices (up to |
| 52 | * \a nslices). The \a compression argument defines the compression algorithm |
| 53 | * used to generate the data in \a slices. |
| 54 | * |
| 55 | * Increases the reference count for all \a slices processed. The user is |
| 56 | * responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/ |
| 57 | GRPCAPI grpc_byte_buffer *grpc_raw_compressed_byte_buffer_create( |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 58 | grpc_slice *slices, size_t nslices, grpc_compression_algorithm compression); |
David Garcia Quintas | 3b31fdf | 2016-07-27 18:17:12 -0700 | [diff] [blame] | 59 | |
| 60 | /** Copies input byte buffer \a bb. |
| 61 | * |
| 62 | * Increases the reference count of all the source slices. The user is |
| 63 | * responsible for calling grpc_byte_buffer_destroy over the returned copy. */ |
| 64 | GRPCAPI grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb); |
| 65 | |
| 66 | /** Returns the size of the given byte buffer, in bytes. */ |
| 67 | GRPCAPI size_t grpc_byte_buffer_length(grpc_byte_buffer *bb); |
| 68 | |
| 69 | /** Destroys \a byte_buffer deallocating all its memory. */ |
| 70 | GRPCAPI void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer); |
| 71 | |
| 72 | /** Reader for byte buffers. Iterates over slices in the byte buffer */ |
| 73 | struct grpc_byte_buffer_reader; |
| 74 | typedef struct grpc_byte_buffer_reader grpc_byte_buffer_reader; |
| 75 | |
| 76 | /** Initialize \a reader to read over \a buffer. |
| 77 | * Returns 1 upon success, 0 otherwise. */ |
| 78 | GRPCAPI int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, |
| 79 | grpc_byte_buffer *buffer); |
| 80 | |
| 81 | /** Cleanup and destroy \a reader */ |
| 82 | GRPCAPI void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader); |
| 83 | |
| 84 | /** Updates \a slice with the next piece of data from from \a reader and returns |
| 85 | * 1. Returns 0 at the end of the stream. Caller is responsible for calling |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 86 | * grpc_slice_unref on the result. */ |
David Garcia Quintas | 3b31fdf | 2016-07-27 18:17:12 -0700 | [diff] [blame] | 87 | GRPCAPI int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader, |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 88 | grpc_slice *slice); |
David Garcia Quintas | 3b31fdf | 2016-07-27 18:17:12 -0700 | [diff] [blame] | 89 | |
| 90 | /** Merge all data from \a reader into single slice */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 91 | GRPCAPI grpc_slice |
David Garcia Quintas | 3b31fdf | 2016-07-27 18:17:12 -0700 | [diff] [blame] | 92 | grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader); |
| 93 | |
| 94 | /** Returns a RAW byte buffer instance from the output of \a reader. */ |
| 95 | GRPCAPI grpc_byte_buffer *grpc_raw_byte_buffer_from_reader( |
| 96 | grpc_byte_buffer_reader *reader); |
| 97 | |
| 98 | #ifdef __cplusplus |
| 99 | } |
| 100 | #endif |
David Garcia Quintas | 59f905d | 2015-06-08 16:31:19 -0700 | [diff] [blame] | 101 | |
Craig Tiller | 9a57633 | 2015-06-17 10:21:49 -0700 | [diff] [blame] | 102 | #endif /* GRPC_BYTE_BUFFER_H */ |