blob: 0d593954dcc32009f732c9bc7be43e6a8c128673 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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 Tiller5b676a62016-10-26 21:09:29 -070034#ifndef GRPC_SLICE_BUFFER_H
35#define GRPC_SLICE_BUFFER_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
Craig Tillerb37d53e2016-10-26 16:16:35 -070037#include <grpc/slice.h>
David Garcia Quintase8fd66b2016-07-27 22:05:37 -070038
39#ifdef __cplusplus
40extern "C" {
41#endif
42
Alexander Polcynd809a152017-05-03 14:49:41 -070043/** initialize a slice buffer */
Craig Tillerd41a4a72016-10-26 16:16:06 -070044GPRAPI void grpc_slice_buffer_init(grpc_slice_buffer *sb);
Alexander Polcynd809a152017-05-03 14:49:41 -070045/** destroy a slice buffer - unrefs any held elements */
Craig Tillerd41a4a72016-10-26 16:16:06 -070046GPRAPI void grpc_slice_buffer_destroy(grpc_slice_buffer *sb);
Alexander Polcynd809a152017-05-03 14:49:41 -070047/** Add an element to a slice buffer - takes ownership of the slice.
David Garcia Quintase8fd66b2016-07-27 22:05:37 -070048 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 Tillerd41a4a72016-10-26 16:16:06 -070050GPRAPI void grpc_slice_buffer_add(grpc_slice_buffer *sb, grpc_slice slice);
Alexander Polcynd809a152017-05-03 14:49:41 -070051/** add an element to a slice buffer - takes ownership of the slice and returns
David Garcia Quintase8fd66b2016-07-27 22:05:37 -070052 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 Tillerd41a4a72016-10-26 16:16:06 -070058GPRAPI size_t grpc_slice_buffer_add_indexed(grpc_slice_buffer *sb,
Craig Tiller28b72422016-10-26 21:15:29 -070059 grpc_slice slice);
Craig Tillerd41a4a72016-10-26 16:16:06 -070060GPRAPI void grpc_slice_buffer_addn(grpc_slice_buffer *sb, grpc_slice *slices,
Craig Tiller28b72422016-10-26 21:15:29 -070061 size_t n);
Alexander Polcynd809a152017-05-03 14:49:41 -070062/** add a very small (less than 8 bytes) amount of data to the end of a slice
David Garcia Quintase8fd66b2016-07-27 22:05:37 -070063 buffer: returns a pointer into which to add the data */
Craig Tillerd41a4a72016-10-26 16:16:06 -070064GPRAPI uint8_t *grpc_slice_buffer_tiny_add(grpc_slice_buffer *sb, size_t len);
Alexander Polcynd809a152017-05-03 14:49:41 -070065/** pop the last buffer, but don't unref it */
Craig Tillerd41a4a72016-10-26 16:16:06 -070066GPRAPI void grpc_slice_buffer_pop(grpc_slice_buffer *sb);
Alexander Polcynd809a152017-05-03 14:49:41 -070067/** clear a slice buffer, unref all elements */
Craig Tillerd41a4a72016-10-26 16:16:06 -070068GPRAPI void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer *sb);
Alexander Polcynd809a152017-05-03 14:49:41 -070069/** swap the contents of two slice buffers */
Craig Tillerd41a4a72016-10-26 16:16:06 -070070GPRAPI void grpc_slice_buffer_swap(grpc_slice_buffer *a, grpc_slice_buffer *b);
Alexander Polcynd809a152017-05-03 14:49:41 -070071/** move all of the elements of src into dst */
Craig Tillerd41a4a72016-10-26 16:16:06 -070072GPRAPI void grpc_slice_buffer_move_into(grpc_slice_buffer *src,
Craig Tiller28b72422016-10-26 21:15:29 -070073 grpc_slice_buffer *dst);
Alexander Polcynd809a152017-05-03 14:49:41 -070074/** remove n bytes from the end of a slice buffer */
Craig Tillerd41a4a72016-10-26 16:16:06 -070075GPRAPI void grpc_slice_buffer_trim_end(grpc_slice_buffer *src, size_t n,
Craig Tiller28b72422016-10-26 21:15:29 -070076 grpc_slice_buffer *garbage);
Alexander Polcynd809a152017-05-03 14:49:41 -070077/** move the first n bytes of src into dst */
Craig Tillerd41a4a72016-10-26 16:16:06 -070078GPRAPI void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n,
Craig Tiller28b72422016-10-26 21:15:29 -070079 grpc_slice_buffer *dst);
Alexander Polcynd809a152017-05-03 14:49:41 -070080/** move the first n bytes of src into dst without adding references */
Craig Tiller423d6fd2017-04-12 13:15:45 -070081GPRAPI void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer *src,
82 size_t n,
83 grpc_slice_buffer *dst);
Alexander Polcynd809a152017-05-03 14:49:41 -070084/** move the first n bytes of src into dst (copying them) */
Craig Tiller7fa7d682017-01-20 16:01:43 -080085GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx *exec_ctx,
86 grpc_slice_buffer *src,
Craig Tillerab4796e2016-12-27 12:36:55 -080087 size_t n, void *dst);
Alexander Polcynd809a152017-05-03 14:49:41 -070088/** take the first slice in the slice buffer */
Craig Tillerd41a4a72016-10-26 16:16:06 -070089GPRAPI grpc_slice grpc_slice_buffer_take_first(grpc_slice_buffer *src);
Alexander Polcynd809a152017-05-03 14:49:41 -070090/** undo the above with (a possibly different) \a slice */
Craig Tillerab4796e2016-12-27 12:36:55 -080091GPRAPI void grpc_slice_buffer_undo_take_first(grpc_slice_buffer *src,
92 grpc_slice slice);
David Garcia Quintase8fd66b2016-07-27 22:05:37 -070093
94#ifdef __cplusplus
95}
96#endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080097
Craig Tiller5b676a62016-10-26 21:09:29 -070098#endif /* GRPC_SLICE_BUFFER_H */