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 | |
Craig Tiller | 5b676a6 | 2016-10-26 21:09:29 -0700 | [diff] [blame] | 34 | #ifndef GRPC_SLICE_BUFFER_H |
| 35 | #define GRPC_SLICE_BUFFER_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
Craig Tiller | b37d53e | 2016-10-26 16:16:35 -0700 | [diff] [blame] | 37 | #include <grpc/slice.h> |
David Garcia Quintas | e8fd66b | 2016-07-27 22:05:37 -0700 | [diff] [blame] | 38 | |
| 39 | #ifdef __cplusplus |
| 40 | extern "C" { |
| 41 | #endif |
| 42 | |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 43 | /** initialize a slice buffer */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 44 | GPRAPI void grpc_slice_buffer_init(grpc_slice_buffer *sb); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 45 | /** destroy a slice buffer - unrefs any held elements */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 46 | GPRAPI void grpc_slice_buffer_destroy(grpc_slice_buffer *sb); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 47 | /** Add an element to a slice buffer - takes ownership of the slice. |
David Garcia Quintas | e8fd66b | 2016-07-27 22:05:37 -0700 | [diff] [blame] | 48 | This function is allowed to concatenate the passed in slice to the end of |
| 49 | some other slice if desired by the slice buffer. */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 50 | GPRAPI void grpc_slice_buffer_add(grpc_slice_buffer *sb, grpc_slice slice); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 51 | /** add an element to a slice buffer - takes ownership of the slice and returns |
David Garcia Quintas | e8fd66b | 2016-07-27 22:05:37 -0700 | [diff] [blame] | 52 | the index of the slice. |
| 53 | Guarantees that the slice will not be concatenated at the end of another |
| 54 | slice (i.e. the data for this slice will begin at the first byte of the |
| 55 | slice at the returned index in sb->slices) |
| 56 | The implementation MAY decide to concatenate data at the end of a small |
| 57 | slice added in this fashion. */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 58 | GPRAPI size_t grpc_slice_buffer_add_indexed(grpc_slice_buffer *sb, |
Craig Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 59 | grpc_slice slice); |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 60 | GPRAPI void grpc_slice_buffer_addn(grpc_slice_buffer *sb, grpc_slice *slices, |
Craig Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 61 | size_t n); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 62 | /** add a very small (less than 8 bytes) amount of data to the end of a slice |
David Garcia Quintas | e8fd66b | 2016-07-27 22:05:37 -0700 | [diff] [blame] | 63 | buffer: returns a pointer into which to add the data */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 64 | GPRAPI uint8_t *grpc_slice_buffer_tiny_add(grpc_slice_buffer *sb, size_t len); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 65 | /** pop the last buffer, but don't unref it */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 66 | GPRAPI void grpc_slice_buffer_pop(grpc_slice_buffer *sb); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 67 | /** clear a slice buffer, unref all elements */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 68 | GPRAPI void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer *sb); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 69 | /** swap the contents of two slice buffers */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 70 | GPRAPI void grpc_slice_buffer_swap(grpc_slice_buffer *a, grpc_slice_buffer *b); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 71 | /** move all of the elements of src into dst */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 72 | GPRAPI void grpc_slice_buffer_move_into(grpc_slice_buffer *src, |
Craig Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 73 | grpc_slice_buffer *dst); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 74 | /** remove n bytes from the end of a slice buffer */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 75 | GPRAPI void grpc_slice_buffer_trim_end(grpc_slice_buffer *src, size_t n, |
Craig Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 76 | grpc_slice_buffer *garbage); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 77 | /** move the first n bytes of src into dst */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 78 | GPRAPI void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n, |
Craig Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 79 | grpc_slice_buffer *dst); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 80 | /** move the first n bytes of src into dst without adding references */ |
Craig Tiller | 423d6fd | 2017-04-12 13:15:45 -0700 | [diff] [blame] | 81 | GPRAPI void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer *src, |
| 82 | size_t n, |
| 83 | grpc_slice_buffer *dst); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 84 | /** move the first n bytes of src into dst (copying them) */ |
Craig Tiller | 7fa7d68 | 2017-01-20 16:01:43 -0800 | [diff] [blame] | 85 | GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx *exec_ctx, |
| 86 | grpc_slice_buffer *src, |
Craig Tiller | ab4796e | 2016-12-27 12:36:55 -0800 | [diff] [blame] | 87 | size_t n, void *dst); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 88 | /** take the first slice in the slice buffer */ |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 89 | GPRAPI grpc_slice grpc_slice_buffer_take_first(grpc_slice_buffer *src); |
Alexander Polcyn | d809a15 | 2017-05-03 14:49:41 -0700 | [diff] [blame] | 90 | /** undo the above with (a possibly different) \a slice */ |
Craig Tiller | ab4796e | 2016-12-27 12:36:55 -0800 | [diff] [blame] | 91 | GPRAPI void grpc_slice_buffer_undo_take_first(grpc_slice_buffer *src, |
| 92 | grpc_slice slice); |
David Garcia Quintas | e8fd66b | 2016-07-27 22:05:37 -0700 | [diff] [blame] | 93 | |
| 94 | #ifdef __cplusplus |
| 95 | } |
| 96 | #endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 97 | |
Craig Tiller | 5b676a6 | 2016-10-26 21:09:29 -0700 | [diff] [blame] | 98 | #endif /* GRPC_SLICE_BUFFER_H */ |