Contiguous buffer views with optional memory ownership.
Classes | |
| class | pw::Buf |
| class | pw::ConstBuf |
Functions | |
| Buf | pw::Slice (Buf &&buf, size_t offset, size_t length) |
Slices a mutable Buf by shifting its start address and setting its size. | |
| Buf | pw::Slice (Buf &&buf, size_t offset) |
| Buf | pw::Truncate (Buf &&buf, size_t length) |
Truncates a mutable Buf to a smaller size. | |
| Buf | pw::Reclaim (Buf &&buf, size_t prefix_count, size_t suffix_count) |
| Buf | pw::ReclaimPrefix (Buf &&buf, size_t count) |
| Buf | pw::ReclaimSuffix (Buf &&buf, size_t count) |
| UniquePtr< std::byte[]> | pw::TakeAllocation (Buf &&buf) |
| ConstBuf | pw::Slice (ConstBuf &&const_buf, size_t offset, size_t length) |
| ConstBuf | pw::Slice (ConstBuf &&const_buf, size_t offset) |
| ConstBuf | pw::Truncate (ConstBuf &&const_buf, size_t length) |
Truncates a ConstBuf to a smaller size. | |
| pw::Buf::Buf (UniquePtr< std::byte[]> &&buffer, size_t offset) | |
| pw::Buf::Buf (UniquePtr< std::byte[]> &&buffer, size_t offset, size_t size) | |
Constructs an owned Buf from a UniquePtr, offset, and size. | |
| static Buf | pw::Buf::Unowned (ByteSpan span, size_t offset, size_t size) |
Creates an unowned Buf from a ByteSpan, offset, and size. | |
| static Buf | pw::Buf::Unowned (ByteSpan span, size_t offset=0) |
|
inlineexplicit |
Constructs an owned Buf using the remaining length starting from offset.
Reclaims prefix_count bytes at the beginning and suffix_count bytes at the end of the buffer.
prefix_count cannot exceed buf.prefix_size(), and suffix_count cannot exceed buf.suffix_size(). Reclaims count prefix bytes at the beginning of the buffer.
count cannot exceed buf.prefix_size(). Reclaims count suffix bytes at the end of the buffer.
count cannot exceed buf.suffix_size(). Slices a mutable Buf by shifting its start address to the end.
offset cannot exceed buf.size(). Slices a ConstBuf by shifting its start address to the end.
offset cannot exceed const_buf.size(). Slices a read-only ConstBuf by shifting its start address and setting its size.
Transfers ownership of a Buf's underlying memory allocation to a UniquePtr. The Buf is null after this call.
The returned UniquePtr spans the entire base allocation (base() and base_size()), not only the bytes in the current view. To preserve the view, record prefix_size() and size() before calling TakeAllocation(), then pass them to Buf(UniquePtr<std::byte[]>&&, size_t, size_t).
To take sole responsibility for the memory, call Release() on the returned UniquePtr after saving its deallocator() and size().
If the Buf is null, returns a null UniquePtr.
buf must be owned (buf.owned()) or null. An unowned Buf has no allocation to take.