diff options
Diffstat (limited to 'include/grpc++/support/slice.h')
-rw-r--r-- | include/grpc++/support/slice.h | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/include/grpc++/support/slice.h b/include/grpc++/support/slice.h index b2343a7f3d..456379cc5b 100644 --- a/include/grpc++/support/slice.h +++ b/include/grpc++/support/slice.h @@ -39,28 +39,42 @@ namespace grpc { +/// A wrapper around \a 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. class Slice GRPC_FINAL { public: - // construct empty slice + /// Construct an empty slice. Slice(); - // destructor - drops one ref + // Destructor - drops one reference. ~Slice(); - // construct slice from grpc slice, adding a ref + enum AddRef { ADD_REF }; + /// Construct a slice from \a slice, adding a reference. Slice(gpr_slice slice, AddRef); - // construct slice from grpc slice, stealing a ref + enum StealRef { STEAL_REF }; + /// Construct a slice from \a slice, stealing a reference. Slice(gpr_slice slice, StealRef); - // copy constructor - adds a ref + + /// Copy constructor, adds a reference. Slice(const Slice& other); - // assignment - ref count is unchanged + + /// Assignment, reference count is unchanged. Slice& operator=(Slice other) { std::swap(slice_, other.slice_); return *this; } + /// Byte size. size_t size() const { return GPR_SLICE_LENGTH(slice_); } + + /// Raw pointer to the beginning (first element) of the slice. const gpr_uint8* begin() const { return GPR_SLICE_START_PTR(slice_); } + + /// Raw pointer to the end (one byte \em past the last element) of the slice. const gpr_uint8* end() const { return GPR_SLICE_END_PTR(slice_); } private: |