34 #ifndef GRPC_SUPPORT_SLICE_H
35 #define GRPC_SUPPORT_SLICE_H
37 #include <grpc/support/sync.h>
65 void (*unref)(
void *);
68 #define GPR_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(gpr_uint8 *) - 1)
88 gpr_uint8 bytes[GPR_SLICE_INLINED_SIZE];
93 #define GPR_SLICE_START_PTR(slice) \
94 ((slice).refcount ? (slice).data.refcounted.bytes \
95 : (slice).data.inlined.bytes)
96 #define GPR_SLICE_LENGTH(slice) \
97 ((slice).refcount ? (slice).data.refcounted.length \
98 : (slice).data.inlined.length)
99 #define GPR_SLICE_SET_LENGTH(slice, newlen) \
100 ((slice).refcount ? ((slice).data.refcounted.length = (newlen)) \
101 : ((slice).data.inlined.length = (newlen)))
102 #define GPR_SLICE_END_PTR(slice) \
103 GPR_SLICE_START_PTR(slice) + GPR_SLICE_LENGTH(slice)
104 #define GPR_SLICE_IS_EMPTY(slice) (GPR_SLICE_LENGTH(slice) == 0)
120 gpr_slice gpr_slice_new(
void *p,
size_t len,
void (*destroy)(
void *));
124 gpr_slice gpr_slice_new_with_len(
void *p,
size_t len,
125 void (*destroy)(
void *,
size_t));
130 gpr_slice gpr_slice_malloc(
size_t length);
138 gpr_slice gpr_slice_from_copied_string(
const char *source);
144 gpr_slice gpr_slice_from_copied_buffer(
const char *source,
size_t len);
172 int gpr_slice_str_cmp(
gpr_slice a,
const char *b);