• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_SLICE_BUFFER_H
20 #define GRPC_SLICE_BUFFER_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include <grpc/slice.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /** initialize a slice buffer */
31 GPRAPI void grpc_slice_buffer_init(grpc_slice_buffer* sb);
32 /** destroy a slice buffer - unrefs any held elements */
33 GPRAPI void grpc_slice_buffer_destroy(grpc_slice_buffer* sb);
34 /** Add an element to a slice buffer - takes ownership of the slice.
35    This function is allowed to concatenate the passed in slice to the end of
36    some other slice if desired by the slice buffer. */
37 GPRAPI void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice);
38 /** add an element to a slice buffer - takes ownership of the slice and returns
39    the index of the slice.
40    Guarantees that the slice will not be concatenated at the end of another
41    slice (i.e. the data for this slice will begin at the first byte of the
42    slice at the returned index in sb->slices)
43    The implementation MAY decide to concatenate data at the end of a small
44    slice added in this fashion. */
45 GPRAPI size_t grpc_slice_buffer_add_indexed(grpc_slice_buffer* sb,
46                                             grpc_slice slice);
47 GPRAPI void grpc_slice_buffer_addn(grpc_slice_buffer* sb, grpc_slice* slices,
48                                    size_t n);
49 /** add a very small (less than 8 bytes) amount of data to the end of a slice
50    buffer: returns a pointer into which to add the data */
51 GPRAPI uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t len);
52 /** pop the last buffer, but don't unref it */
53 GPRAPI void grpc_slice_buffer_pop(grpc_slice_buffer* sb);
54 /** clear a slice buffer, unref all elements */
55 GPRAPI void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb);
56 /** swap the contents of two slice buffers */
57 GPRAPI void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b);
58 /** move all of the elements of src into dst */
59 GPRAPI void grpc_slice_buffer_move_into(grpc_slice_buffer* src,
60                                         grpc_slice_buffer* dst);
61 /** remove n bytes from the end of a slice buffer */
62 GPRAPI void grpc_slice_buffer_trim_end(grpc_slice_buffer* src, size_t n,
63                                        grpc_slice_buffer* garbage);
64 /** move the first n bytes of src into dst */
65 GPRAPI void grpc_slice_buffer_move_first(grpc_slice_buffer* src, size_t n,
66                                          grpc_slice_buffer* dst);
67 /** move the first n bytes of src into dst without adding references */
68 GPRAPI void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src,
69                                                 size_t n,
70                                                 grpc_slice_buffer* dst);
71 /** move the first n bytes of src into dst (copying them) */
72 GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src,
73                                                      size_t n, void* dst);
74 /** take the first slice in the slice buffer */
75 GPRAPI grpc_slice grpc_slice_buffer_take_first(grpc_slice_buffer* src);
76 /** undo the above with (a possibly different) \a slice */
77 GPRAPI void grpc_slice_buffer_undo_take_first(grpc_slice_buffer* src,
78                                               grpc_slice slice);
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif /* GRPC_SLICE_BUFFER_H */
85