include/grpc/impl/codegen/slice.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_CODEGEN_SLICE_H
20 #define GRPC_IMPL_CODEGEN_SLICE_H
21 
22 // IWYU pragma: private
23 
25 
26 #include <stddef.h>
27 
29 
30 typedef struct grpc_slice grpc_slice;
31 
45 /* Inlined half of grpc_slice is allowed to expand the size of the overall type
46  by this many bytes */
47 #define GRPC_SLICE_INLINE_EXTRA_SIZE sizeof(void*)
48 
49 #define GRPC_SLICE_INLINED_SIZE \
50  (sizeof(size_t) + sizeof(uint8_t*) - 1 + GRPC_SLICE_INLINE_EXTRA_SIZE)
51 
52 struct grpc_slice_refcount;
65 struct grpc_slice {
69  size_t length;
71  } refcounted;
75  } inlined;
76  } data;
77 };
78 
79 #define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 8
80 
83 typedef struct grpc_slice_buffer {
87 
91  size_t count;
94  size_t capacity;
96  size_t length;
100 
101 #define GRPC_SLICE_START_PTR(slice) \
102  ((slice).refcount ? (slice).data.refcounted.bytes \
103  : (slice).data.inlined.bytes)
104 #define GRPC_SLICE_LENGTH(slice) \
105  ((slice).refcount ? (slice).data.refcounted.length \
106  : (slice).data.inlined.length)
107 #define GRPC_SLICE_SET_LENGTH(slice, newlen) \
108  ((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \
109  : ((slice).data.inlined.length = (uint8_t)(newlen)))
110 #define GRPC_SLICE_END_PTR(slice) \
111  GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice)
112 #define GRPC_SLICE_IS_EMPTY(slice) (GRPC_SLICE_LENGTH(slice) == 0)
113 
114 #ifdef GRPC_ALLOW_GPR_SLICE_FUNCTIONS
115 
116 /* Duplicate GPR_* definitions */
117 #define GPR_SLICE_START_PTR(slice) \
118  ((slice).refcount ? (slice).data.refcounted.bytes \
119  : (slice).data.inlined.bytes)
120 #define GPR_SLICE_LENGTH(slice) \
121  ((slice).refcount ? (slice).data.refcounted.length \
122  : (slice).data.inlined.length)
123 #define GPR_SLICE_SET_LENGTH(slice, newlen) \
124  ((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \
125  : ((slice).data.inlined.length = (uint8_t)(newlen)))
126 #define GPR_SLICE_END_PTR(slice) \
127  GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice)
128 #define GPR_SLICE_IS_EMPTY(slice) (GRPC_SLICE_LENGTH(slice) == 0)
129 
130 #endif /* GRPC_ALLOW_GPR_SLICE_FUNCTIONS */
131 
132 #endif /* GRPC_IMPL_CODEGEN_SLICE_H */
grpc_slice::refcount
struct grpc_slice_refcount * refcount
Definition: include/grpc/impl/codegen/slice.h:66
grpc_slice::grpc_slice_data::grpc_slice_refcounted::length
size_t length
Definition: include/grpc/impl/codegen/slice.h:69
grpc_slice::grpc_slice_data::grpc_slice_refcounted
Definition: include/grpc/impl/codegen/slice.h:68
grpc_slice_buffer::slices
grpc_slice * slices
Definition: include/grpc/impl/codegen/slice.h:89
grpc_slice::grpc_slice_data::grpc_slice_inlined
Definition: include/grpc/impl/codegen/slice.h:72
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
grpc_slice::grpc_slice_data
Definition: include/grpc/impl/codegen/slice.h:67
grpc_slice::grpc_slice_data::grpc_slice_inlined::length
uint8_t length
Definition: include/grpc/impl/codegen/slice.h:73
grpc_slice_buffer::count
size_t count
Definition: include/grpc/impl/codegen/slice.h:91
grpc_slice_refcount
Definition: slice_refcount_base.h:25
grpc_slice::grpc_slice_data::inlined
struct grpc_slice::grpc_slice_data::grpc_slice_inlined inlined
grpc_slice_buffer::length
size_t length
Definition: include/grpc/impl/codegen/slice.h:96
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
grpc_slice::grpc_slice_data::refcounted
struct grpc_slice::grpc_slice_data::grpc_slice_refcounted refcounted
port_platform.h
grpc_slice::data
union grpc_slice::grpc_slice_data data
GRPC_SLICE_BUFFER_INLINE_ELEMENTS
#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS
Definition: include/grpc/impl/codegen/slice.h:79
GRPC_SLICE_INLINED_SIZE
#define GRPC_SLICE_INLINED_SIZE
Definition: include/grpc/impl/codegen/slice.h:49
grpc_slice::grpc_slice_data::grpc_slice_inlined::bytes
uint8_t bytes[GRPC_SLICE_INLINED_SIZE]
Definition: include/grpc/impl/codegen/slice.h:74
grpc_slice_buffer
struct grpc_slice_buffer grpc_slice_buffer
grpc_slice_buffer::base_slices
grpc_slice * base_slices
Definition: include/grpc/impl/codegen/slice.h:86
grpc_slice_buffer::inlined
grpc_slice inlined[GRPC_SLICE_BUFFER_INLINE_ELEMENTS]
Definition: include/grpc/impl/codegen/slice.h:98
grpc_slice::grpc_slice_data::grpc_slice_refcounted::bytes
uint8_t * bytes
Definition: include/grpc/impl/codegen/slice.h:70
grpc_slice_buffer::capacity
size_t capacity
Definition: include/grpc/impl/codegen/slice.h:94
gpr_slice.h
grpc_slice_buffer
Definition: include/grpc/impl/codegen/slice.h:83


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:18