Public Types | Public Member Functions | Private Attributes | Friends | List of all members
grpc::Slice Class Referencefinal

#include <slice.h>

Public Types

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

Public Member Functions

const uint8_tbegin () const
 Raw pointer to the beginning (first element) of the slice. More...
 
grpc_slice c_slice () const
 Raw C slice. Caller needs to call grpc_slice_unref when done. More...
 
const uint8_tend () const
 Raw pointer to the end (one byte past the last element) of the slice. More...
 
Sliceoperator= (Slice other)
 Assignment, reference count is unchanged. More...
 
size_t size () const
 Byte size. More...
 
 Slice ()
 Construct an empty slice. More...
 
 Slice (const Slice &other)
 Copy constructor, adds a reference. More...
 
 Slice (const std::string &str)
 Construct a slice from a copied string. More...
 
 Slice (const void *buf, size_t len)
 Construct a slice from a copied buffer. More...
 
 Slice (const void *buf, size_t len, StaticSlice)
 Construct a slice from a static buffer. 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 (Slice &&other) noexcept
 Move constructor, steals a reference. 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 *), void *user_data)
 
 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...
 
Slice sub (size_t begin, size_t end) const
 Returns a substring of the slice as another slice. More...
 
 ~Slice ()
 Destructor - drops one reference. More...
 

Private Attributes

grpc_slice slice_
 

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.

Definition at line 36 of file include/grpcpp/impl/codegen/slice.h.

Member Enumeration Documentation

◆ AddRef

Enumerator
ADD_REF 

Definition at line 43 of file include/grpcpp/impl/codegen/slice.h.

◆ StaticSlice

Enumerator
STATIC_SLICE 

Definition at line 67 of file include/grpcpp/impl/codegen/slice.h.

◆ StealRef

Enumerator
STEAL_REF 

Definition at line 48 of file include/grpcpp/impl/codegen/slice.h.

Constructor & Destructor Documentation

◆ Slice() [1/12]

grpc::Slice::Slice ( )
inline

Construct an empty slice.

Definition at line 39 of file include/grpcpp/impl/codegen/slice.h.

◆ ~Slice()

grpc::Slice::~Slice ( )
inline

Destructor - drops one reference.

Definition at line 41 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [2/12]

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

Construct a slice from slice, adding a reference.

Definition at line 45 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [3/12]

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

Construct a slice from slice, stealing a reference.

Definition at line 50 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [4/12]

grpc::Slice::Slice ( size_t  len)
inlineexplicit

Allocate a slice of specified size.

Definition at line 53 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [5/12]

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

Construct a slice from a copied buffer.

Definition at line 57 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [6/12]

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

Construct a slice from a copied string.

Definition at line 63 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [7/12]

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

Construct a slice from a static buffer.

Definition at line 70 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [8/12]

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

Copy constructor, adds a reference.

Definition at line 75 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [9/12]

grpc::Slice::Slice ( Slice &&  other)
inlinenoexcept

Move constructor, steals a reference.

Definition at line 79 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [10/12]

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)

Definition at line 94 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [11/12]

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

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

Definition at line 99 of file include/grpcpp/impl/codegen/slice.h.

◆ Slice() [12/12]

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.

Definition at line 103 of file include/grpcpp/impl/codegen/slice.h.

Member Function Documentation

◆ begin()

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

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

Definition at line 111 of file include/grpcpp/impl/codegen/slice.h.

◆ c_slice()

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

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

Definition at line 123 of file include/grpcpp/impl/codegen/slice.h.

◆ end()

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

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

Definition at line 114 of file include/grpcpp/impl/codegen/slice.h.

◆ operator=()

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

Assignment, reference count is unchanged.

Definition at line 84 of file include/grpcpp/impl/codegen/slice.h.

◆ size()

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

Byte size.

Definition at line 108 of file include/grpcpp/impl/codegen/slice.h.

◆ sub()

Slice grpc::Slice::sub ( size_t  begin,
size_t  end 
) const
inline

Returns a substring of the slice as another slice.

Definition at line 117 of file include/grpcpp/impl/codegen/slice.h.

Friends And Related Function Documentation

◆ ByteBuffer

friend class ByteBuffer
friend

Definition at line 128 of file include/grpcpp/impl/codegen/slice.h.

Member Data Documentation

◆ slice_

grpc_slice grpc::Slice::slice_
private

Definition at line 130 of file include/grpcpp/impl/codegen/slice.h.


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


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:31