GRPC C++  1.62.0
slice_type.h
Go to the documentation of this file.
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_IMPL_SLICE_TYPE_H
20 #define GRPC_IMPL_SLICE_TYPE_H
21 
22 // IWYU pragma: private, include <grpc/slice.h>
23 
25 
26 #include <stddef.h>
27 
28 typedef struct grpc_slice grpc_slice;
29 
43 /* Inlined half of grpc_slice is allowed to expand the size of the overall type
44  by this many bytes */
45 #define GRPC_SLICE_INLINE_EXTRA_SIZE sizeof(void*)
46 
47 #define GRPC_SLICE_INLINED_SIZE \
48  (sizeof(size_t) + sizeof(uint8_t*) - 1 + GRPC_SLICE_INLINE_EXTRA_SIZE)
49 
50 struct grpc_slice_refcount;
63 struct grpc_slice {
64  struct grpc_slice_refcount* refcount;
67  size_t length;
68  uint8_t* bytes;
69  } refcounted;
71  uint8_t length;
73  } inlined;
74  } data;
75 };
76 
77 #define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 6
78 
81 typedef struct grpc_slice_buffer {
85 
89  size_t count;
92  size_t capacity;
94  size_t length;
98 
99 #define GRPC_SLICE_START_PTR(slice) \
100  ((slice).refcount ? (slice).data.refcounted.bytes \
101  : (slice).data.inlined.bytes)
102 #define GRPC_SLICE_LENGTH(slice) \
103  ((slice).refcount ? (slice).data.refcounted.length \
104  : (slice).data.inlined.length)
105 #define GRPC_SLICE_SET_LENGTH(slice, newlen) \
106  ((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \
107  : ((slice).data.inlined.length = (uint8_t)(newlen)))
108 #define GRPC_SLICE_END_PTR(slice) \
109  GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice)
110 #define GRPC_SLICE_IS_EMPTY(slice) (GRPC_SLICE_LENGTH(slice) == 0)
111 
112 #endif /* GRPC_IMPL_SLICE_TYPE_H */
grpc_slice::grpc_slice_data::grpc_slice_inlined::bytes
uint8_t bytes[(sizeof(size_t)+sizeof(uint8_t *) - 1+sizeof(void *))]
Definition: slice_type.h:72
GRPC_SLICE_BUFFER_INLINE_ELEMENTS
#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS
Definition: slice_type.h:77
grpc_slice::refcount
struct grpc_slice_refcount * refcount
Definition: slice_type.h:64
grpc_slice::grpc_slice_data::grpc_slice_refcounted::length
size_t length
Definition: slice_type.h:67
grpc_slice::grpc_slice_data::grpc_slice_refcounted
Definition: slice_type.h:66
grpc_slice_buffer::slices
grpc_slice * slices
slices in the array (Points to the first valid grpc_slice in the array)
Definition: slice_type.h:87
grpc_slice::grpc_slice_data::grpc_slice_inlined
Definition: slice_type.h:70
grpc_slice::grpc_slice_data
Definition: slice_type.h:65
grpc_slice::grpc_slice_data::grpc_slice_inlined::length
uint8_t length
Definition: slice_type.h:71
grpc_slice_buffer::count
size_t count
the number of slices in the array
Definition: slice_type.h:89
grpc_slice::grpc_slice_data::inlined
struct grpc_slice::grpc_slice_data::grpc_slice_inlined inlined
grpc_slice_buffer::length
size_t length
the combined length of all slices in the array
Definition: slice_type.h:94
grpc_slice
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice_type.h:63
grpc_slice::grpc_slice_data::refcounted
struct grpc_slice::grpc_slice_data::grpc_slice_refcounted refcounted
grpc_slice::data
union grpc_slice::grpc_slice_data data
grpc_slice_buffer::base_slices
grpc_slice * base_slices
This is for internal use only.
Definition: slice_type.h:84
grpc_slice::grpc_slice_data::grpc_slice_refcounted::bytes
uint8_t * bytes
Definition: slice_type.h:68
grpc_slice_buffer::capacity
size_t capacity
the number of slices allocated in the array.
Definition: slice_type.h:92
grpc_slice_buffer
Represents an expandable array of slices, to be interpreted as a single item.
Definition: slice_type.h:81
grpc_slice_buffer::inlined
grpc_slice inlined[6]
inlined elements to avoid allocations
Definition: slice_type.h:96
GRPC_SLICE_INLINED_SIZE
#define GRPC_SLICE_INLINED_SIZE
Definition: slice_type.h:47
grpc_slice_buffer
struct grpc_slice_buffer grpc_slice_buffer
Represents an expandable array of slices, to be interpreted as a single item.
port_platform.h