• Home
  • Raw
  • Download

Lines Matching full:slice

22 #include <grpc/slice.h>
30 /// A slice represents a contiguous reference counted array of bytes.
31 /// It is cheap to take references to a slice, and it is cheap to create a
32 /// slice pointing to a subset of another slice.
33 class Slice final {
35 /// Construct an empty slice.
36 Slice() : slice_(grpc_empty_slice()) {} in Slice() function
38 ~Slice() { grpc_slice_unref(slice_); } in ~Slice()
41 /// Construct a slice from \a slice, adding a reference.
42 Slice(grpc_slice slice, AddRef) : slice_(grpc_slice_ref(slice)) {} in Slice() argument
45 /// Construct a slice from \a slice, stealing a reference.
46 Slice(grpc_slice slice, StealRef) : slice_(slice) {} in Slice() argument
48 /// Allocate a slice of specified size
49 explicit Slice(size_t len) : slice_(grpc_slice_malloc(len)) {} in Slice() function
51 /// Construct a slice from a copied buffer
52 Slice(const void* buf, size_t len) in Slice() function
56 /// Construct a slice from a copied string
58 Slice(const std::string& str) in Slice() function
63 /// Construct a slice from a static buffer
64 Slice(const void* buf, size_t len, StaticSlice) in Slice() function
69 Slice(const Slice& other) : slice_(grpc_slice_ref(other.slice_)) {} in Slice() function
72 Slice(Slice&& other) noexcept : slice_(other.slice_) { in Slice() function
77 Slice& operator=(Slice other) {
82 /// Create a slice pointing at some data. Calls malloc to allocate a refcount
87 Slice(void* buf, size_t len, void (*destroy)(void*), void* user_data) in Slice() function
91 Slice(void* buf, size_t len, void (*destroy)(void*)) in Slice() function
92 : Slice(buf, len, destroy, buf) {} in Slice()
94 /// Similar to the above but has a destroy that also takes slice length
95 Slice(void* buf, size_t len, void (*destroy)(void*, size_t)) in Slice() function
101 /// Raw pointer to the beginning (first element) of the slice.
104 /// Raw pointer to the end (one byte \em past the last element) of the slice.
107 /// Returns a substring of the `slice` as another slice.
108 Slice sub(size_t begin, size_t end) const { in sub()
109 return Slice(grpc_slice_sub(slice_, begin, end), STEAL_REF); in sub()
112 /// Raw C slice. Caller needs to call grpc_slice_unref when done.
121 inline grpc::string_ref StringRefFromSlice(const grpc_slice* slice) { in StringRefFromSlice() argument
123 reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(*slice)), in StringRefFromSlice()
124 GRPC_SLICE_LENGTH(*slice)); in StringRefFromSlice()
127 inline std::string StringFromCopiedSlice(grpc_slice slice) { in StringFromCopiedSlice() argument
128 return std::string(reinterpret_cast<char*>(GRPC_SLICE_START_PTR(slice)), in StringFromCopiedSlice()
129 GRPC_SLICE_LENGTH(slice)); in StringFromCopiedSlice()