GRPC Core  6.0.0
Data Structures | Macros | Typedefs
slice.h File Reference
#include <grpc/impl/codegen/port_platform.h>
#include <stddef.h>
#include <grpc/impl/codegen/gpr_slice.h>

Go to the source code of this file.

Data Structures

struct  grpc_slice_refcount_vtable
 Slice API. More...
 
struct  grpc_slice_refcount
 Reference count container for grpc_slice. More...
 
struct  grpc_slice
 A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1]. More...
 
union  grpc_slice::grpc_slice_data
 
struct  grpc_slice::grpc_slice_data::grpc_slice_refcounted
 
struct  grpc_slice::grpc_slice_data::grpc_slice_inlined
 
struct  grpc_slice_buffer
 Represents an expandable array of slices, to be interpreted as a single item. More...
 

Macros

#define GRPC_SLICE_INLINE_EXTRA_SIZE   sizeof(void*)
 
#define GRPC_SLICE_INLINED_SIZE   (sizeof(size_t) + sizeof(uint8_t*) - 1 + GRPC_SLICE_INLINE_EXTRA_SIZE)
 
#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS   8
 
#define GRPC_SLICE_START_PTR(slice)
 
#define GRPC_SLICE_LENGTH(slice)
 
#define GRPC_SLICE_SET_LENGTH(slice, newlen)
 
#define GRPC_SLICE_END_PTR(slice)   GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice)
 
#define GRPC_SLICE_IS_EMPTY(slice)   (GRPC_SLICE_LENGTH(slice) == 0)
 

Typedefs

typedef struct grpc_slice grpc_slice
 
typedef struct grpc_slice_refcount_vtable grpc_slice_refcount_vtable
 Slice API. More...
 
typedef struct grpc_slice_refcount grpc_slice_refcount
 Reference count container for grpc_slice. More...
 
typedef struct grpc_slice_buffer grpc_slice_buffer
 Represents an expandable array of slices, to be interpreted as a single item. More...
 

Macro Definition Documentation

◆ GRPC_SLICE_BUFFER_INLINE_ELEMENTS

#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS   8

◆ GRPC_SLICE_END_PTR

#define GRPC_SLICE_END_PTR (   slice)    GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice)

◆ GRPC_SLICE_INLINE_EXTRA_SIZE

#define GRPC_SLICE_INLINE_EXTRA_SIZE   sizeof(void*)

◆ GRPC_SLICE_INLINED_SIZE

#define GRPC_SLICE_INLINED_SIZE   (sizeof(size_t) + sizeof(uint8_t*) - 1 + GRPC_SLICE_INLINE_EXTRA_SIZE)

◆ GRPC_SLICE_IS_EMPTY

#define GRPC_SLICE_IS_EMPTY (   slice)    (GRPC_SLICE_LENGTH(slice) == 0)

◆ GRPC_SLICE_LENGTH

#define GRPC_SLICE_LENGTH (   slice)
Value:
((slice).refcount ? (slice).data.refcounted.length \
: (slice).data.inlined.length)

◆ GRPC_SLICE_SET_LENGTH

#define GRPC_SLICE_SET_LENGTH (   slice,
  newlen 
)
Value:
((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \
: ((slice).data.inlined.length = (uint8_t)(newlen)))

◆ GRPC_SLICE_START_PTR

#define GRPC_SLICE_START_PTR (   slice)
Value:
((slice).refcount ? (slice).data.refcounted.bytes \
: (slice).data.inlined.bytes)

Typedef Documentation

◆ grpc_slice

typedef struct grpc_slice grpc_slice

◆ grpc_slice_buffer

Represents an expandable array of slices, to be interpreted as a single item.

◆ grpc_slice_refcount

Reference count container for grpc_slice.

Contains function pointers to increment and decrement reference counts. Implementations should cleanup when the reference count drops to zero. Typically client code should not touch this, and use grpc_slice_malloc, grpc_slice_new, or grpc_slice_new_with_len instead.

◆ grpc_slice_refcount_vtable

Slice API.

A slice represents a contiguous reference counted array of bytes. It is cheap to take references to a slice, and it is cheap to create a slice pointing to a subset of another slice.

The data-structure for slices is exposed here to allow non-gpr code to build slices from whatever data they have available.

When defining interfaces that handle slices, care should be taken to define reference ownership semantics (who should call unref?) and mutability constraints (is the callee allowed to modify the slice?)