GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

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, 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_SUPPORT_SLICE_BUFFER_H
35 #define GRPC_SUPPORT_SLICE_BUFFER_H
36
37 #include <grpc/support/slice.h>
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 */
50 gpr_slice *slices;
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 */
58 gpr_slice inlined[GRPC_SLICE_BUFFER_INLINE_ELEMENTS];
59 } gpr_slice_buffer;
60
61 /* initialize a slice buffer */
62 void gpr_slice_buffer_init(gpr_slice_buffer *sb);
63 /* destroy a slice buffer - unrefs any held elements */
64 void gpr_slice_buffer_destroy(gpr_slice_buffer *sb);
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. */
68 void gpr_slice_buffer_add(gpr_slice_buffer *sb, gpr_slice slice);
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 size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, gpr_slice slice);
77 void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, size_t n);
78 /* add a very small (less than 8 bytes) amount of data to the end of a slice
79 buffer: returns a pointer into which to add the data */
80 gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned len);
81 /* pop the last buffer, but don't unref it */
82 void gpr_slice_buffer_pop(gpr_slice_buffer *sb);
83 /* clear a slice buffer, unref all elements */
84 void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb);
85 /* swap the contents of two slice buffers */
86 void gpr_slice_buffer_swap(gpr_slice_buffer *a, gpr_slice_buffer *b);
87 /* move all of the elements of src into dst */
88 void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst);
89
90 #ifdef __cplusplus
91 }
92 #endif
93
94 #endif /* GRPC_SUPPORT_SLICE_BUFFER_H */
gpr_slice_buffer_tiny_add
gpr_uint8 * gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned len)
gpr_slice_buffer::slices
gpr_slice * slices
Definition: slice_buffer.h:50
gpr_uint8
uint8_t gpr_uint8
Definition: port_platform.h:307
gpr_slice_buffer_add_indexed
size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, gpr_slice slice)
gpr_slice_buffer::length
size_t length
Definition: slice_buffer.h:56
gpr_slice_buffer::capacity
size_t capacity
Definition: slice_buffer.h:54
gpr_slice_buffer_reset_and_unref
void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb)
gpr_slice_buffer_init
void gpr_slice_buffer_init(gpr_slice_buffer *sb)
gpr_slice_buffer_pop
void gpr_slice_buffer_pop(gpr_slice_buffer *sb)
gpr_slice_buffer_add
void gpr_slice_buffer_add(gpr_slice_buffer *sb, gpr_slice slice)
gpr_slice_buffer
Definition: slice_buffer.h:48
gpr_slice_buffer::count
size_t count
Definition: slice_buffer.h:52
gpr_slice_buffer_destroy
void gpr_slice_buffer_destroy(gpr_slice_buffer *sb)
gpr_slice_buffer_swap
void gpr_slice_buffer_swap(gpr_slice_buffer *a, gpr_slice_buffer *b)
gpr_slice_buffer_addn
void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, size_t n)
gpr_slice_buffer_move_into
void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst)
GRPC_SLICE_BUFFER_INLINE_ELEMENTS
#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS
Definition: slice_buffer.h:43
slice.h
gpr_slice
Definition: slice.h:79