GRPC Core  0.13.1-pre1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
slice_buffer.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015-2016, Google Inc.
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 
34 #ifndef GRPC_IMPL_CODEGEN_SLICE_BUFFER_H
35 #define GRPC_IMPL_CODEGEN_SLICE_BUFFER_H
36 
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 8
44 
45 /* Represents an expandable array of slices, to be interpreted as a single item
46  TODO(ctiller): inline some small number of elements into the struct, to
47  avoid per-call allocations */
48 typedef struct {
49  /* slices in the array */
51  /* the number of slices in the array */
52  size_t count;
53  /* the number of slices allocated in the array */
54  size_t capacity;
55  /* the combined length of all slices in the array */
56  size_t length;
57  /* inlined elements to avoid allocations */
60 
61 /* initialize a slice buffer */
63 /* destroy a slice buffer - unrefs any held elements */
65 /* Add an element to a slice buffer - takes ownership of the slice.
66  This function is allowed to concatenate the passed in slice to the end of
67  some other slice if desired by the slice buffer. */
69 /* add an element to a slice buffer - takes ownership of the slice and returns
70  the index of the slice.
71  Guarantees that the slice will not be concatenated at the end of another
72  slice (i.e. the data for this slice will begin at the first byte of the
73  slice at the returned index in sb->slices)
74  The implementation MAY decide to concatenate data at the end of a small
75  slice added in this fashion. */
76 GPRAPI size_t
79  size_t n);
80 /* add a very small (less than 8 bytes) amount of data to the end of a slice
81  buffer: returns a pointer into which to add the data */
82 GPRAPI uint8_t *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t len);
83 /* pop the last buffer, but don't unref it */
85 /* clear a slice buffer, unref all elements */
87 /* swap the contents of two slice buffers */
89 /* move all of the elements of src into dst */
91  gpr_slice_buffer *dst);
92 /* remove n bytes from the end of a slice buffer */
94  gpr_slice_buffer *garbage);
95 /* move the first n bytes of src into dst */
97  gpr_slice_buffer *dst);
98 /* take the first slice in the slice buffer */
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif /* GRPC_IMPL_CODEGEN_SLICE_BUFFER_H */
GPRAPI void gpr_slice_buffer_trim_end(gpr_slice_buffer *src, size_t n, gpr_slice_buffer *garbage)
gpr_slice * slices
Definition: slice_buffer.h:50
GPRAPI size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, gpr_slice slice)
GPRAPI uint8_t * gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t len)
size_t length
Definition: slice_buffer.h:56
#define GPRAPI
Definition: port_platform.h:359
size_t capacity
Definition: slice_buffer.h:54
GPRAPI void gpr_slice_buffer_add(gpr_slice_buffer *sb, gpr_slice slice)
Definition: slice_buffer.h:48
GPRAPI void gpr_slice_buffer_swap(gpr_slice_buffer *a, gpr_slice_buffer *b)
GPRAPI void gpr_slice_buffer_pop(gpr_slice_buffer *sb)
size_t count
Definition: slice_buffer.h:52
#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS
Definition: slice_buffer.h:43
GPRAPI void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb)
GPRAPI void gpr_slice_buffer_destroy(gpr_slice_buffer *sb)
GPRAPI gpr_slice gpr_slice_buffer_take_first(gpr_slice_buffer *src)
GPRAPI void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, size_t n)
GPRAPI void gpr_slice_buffer_move_first(gpr_slice_buffer *src, size_t n, gpr_slice_buffer *dst)
GPRAPI void gpr_slice_buffer_init(gpr_slice_buffer *sb)
GPRAPI void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst)
Definition: slice.h:79