GRPC C++  1.30.0
Public Types | Public Member Functions | Friends
grpc::Slice Class Referencefinal

A wrapper around grpc_slice. More...

#include <slice.h>

Public Types

enum  AddRef { ADD_REF }
 
enum  StealRef { STEAL_REF }
 
enum  StaticSlice { STATIC_SLICE }
 

Public Member Functions

 Slice ()
 Construct an empty slice. More...
 
 ~Slice ()
 Destructor - drops one reference. More...
 
 Slice (grpc_slice slice, AddRef)
 Construct a slice from slice, adding a reference. More...
 
 Slice (grpc_slice slice, StealRef)
 Construct a slice from slice, stealing a reference. More...
 
 Slice (size_t len)
 Allocate a slice of specified size. More...
 
 Slice (const void *buf, size_t len)
 Construct a slice from a copied buffer. More...
 
 Slice (const grpc::string &str)
 Construct a slice from a copied string. More...
 
 Slice (const void *buf, size_t len, StaticSlice)
 Construct a slice from a static buffer. More...
 
 Slice (const Slice &other)
 Copy constructor, adds a reference. More...
 
Sliceoperator= (Slice other)
 Assignment, reference count is unchanged. More...
 
 Slice (void *buf, size_t len, void(*destroy)(void *), void *user_data)
 Create a slice pointing at some data. More...
 
 Slice (void *buf, size_t len, void(*destroy)(void *))
 Specialization of above for common case where buf == user_data. More...
 
 Slice (void *buf, size_t len, void(*destroy)(void *, size_t))
 Similar to the above but has a destroy that also takes slice length. More...
 
size_t size () const
 Byte size. More...
 
const uint8_t * begin () const
 Raw pointer to the beginning (first element) of the slice. More...
 
const uint8_t * end () const
 Raw pointer to the end (one byte past the last element) of the slice. More...
 
grpc_slice c_slice () const
 Raw C slice. Caller needs to call grpc_slice_unref when done. More...
 

Friends

class ByteBuffer
 

Detailed Description

A wrapper around grpc_slice.

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.

Member Enumeration Documentation

◆ AddRef

Enumerator
ADD_REF 

◆ StaticSlice

Enumerator
STATIC_SLICE 

◆ StealRef

Enumerator
STEAL_REF 

Constructor & Destructor Documentation

◆ Slice() [1/11]

grpc::Slice::Slice ( )
inline

Construct an empty slice.

◆ ~Slice()

grpc::Slice::~Slice ( )
inline

Destructor - drops one reference.

◆ Slice() [2/11]

grpc::Slice::Slice ( grpc_slice  slice,
AddRef   
)
inline

Construct a slice from slice, adding a reference.

◆ Slice() [3/11]

grpc::Slice::Slice ( grpc_slice  slice,
StealRef   
)
inline

Construct a slice from slice, stealing a reference.

◆ Slice() [4/11]

grpc::Slice::Slice ( size_t  len)
inline

Allocate a slice of specified size.

◆ Slice() [5/11]

grpc::Slice::Slice ( const void *  buf,
size_t  len 
)
inline

Construct a slice from a copied buffer.

◆ Slice() [6/11]

grpc::Slice::Slice ( const grpc::string str)
inline

Construct a slice from a copied string.

◆ Slice() [7/11]

grpc::Slice::Slice ( const void *  buf,
size_t  len,
StaticSlice   
)
inline

Construct a slice from a static buffer.

◆ Slice() [8/11]

grpc::Slice::Slice ( const Slice other)
inline

Copy constructor, adds a reference.

◆ Slice() [9/11]

grpc::Slice::Slice ( void *  buf,
size_t  len,
void(*)(void *)  destroy,
void *  user_data 
)
inline

Create a slice pointing at some data.

Calls malloc to allocate a refcount for the object, and arranges that destroy will be called with the user data pointer passed in at destruction. Can be the same as buf or different (e.g., if data is part of a larger structure that must be destroyed when the data is no longer needed)

◆ Slice() [10/11]

grpc::Slice::Slice ( void *  buf,
size_t  len,
void(*)(void *)  destroy 
)
inline

Specialization of above for common case where buf == user_data.

◆ Slice() [11/11]

grpc::Slice::Slice ( void *  buf,
size_t  len,
void(*)(void *, size_t)  destroy 
)
inline

Similar to the above but has a destroy that also takes slice length.

Member Function Documentation

◆ begin()

const uint8_t* grpc::Slice::begin ( ) const
inline

Raw pointer to the beginning (first element) of the slice.

◆ c_slice()

grpc_slice grpc::Slice::c_slice ( ) const
inline

Raw C slice. Caller needs to call grpc_slice_unref when done.

◆ end()

const uint8_t* grpc::Slice::end ( ) const
inline

Raw pointer to the end (one byte past the last element) of the slice.

◆ operator=()

Slice& grpc::Slice::operator= ( Slice  other)
inline

Assignment, reference count is unchanged.

◆ size()

size_t grpc::Slice::size ( ) const
inline

Byte size.

Friends And Related Function Documentation

◆ ByteBuffer

friend class ByteBuffer
friend

The documentation for this class was generated from the following file: