12#ifndef ROC_CORE_SLICE_H_
13#define ROC_CORE_SLICE_H_
68 data_ = (T*)buffer->
data();
69 size_ = buffer->
size() /
sizeof(T);
79 roc_panic(
"slice: invalid range: [%lu,%lu)", (
unsigned long)
from,
82 if (
to > buffer.
size() /
sizeof(T)) {
83 roc_panic(
"slice: out of bounds: available=[%lu,%lu) requested=[%lu,%lu)",
84 (
unsigned long)0, (
unsigned long)buffer.
size() /
sizeof(T),
85 (
unsigned long)
from, (
unsigned long)
to);
105 return data_ + size_;
118 return buffer_->
size() /
sizeof(T) -
size_t(data_ - (T*)buffer_->
data());
129 roc_panic(
"slice: invalid range: [%lu,%lu)", (
unsigned long)
from,
133 roc_panic(
"slice: out of bounds: available=[%lu,%lu) requested=[%lu,%lu)",
134 (
unsigned long)0, (
unsigned long)
cap, (
unsigned long)
from,
138 data_ = data_ +
from;
151 roc_panic(
"slice: extend with zero size");
153 T*
ret = data_ + size_;
164 roc_panic(
"slice: invalid range: [%lu,%lu)", (
unsigned long)
from,
168 roc_panic(
"slice: out of bounds: available=[%lu,%lu) requested=[%lu,%lu)",
169 (
unsigned long)0, (
unsigned long)size_, (
unsigned long)
from,
173 ret.buffer_ = buffer_;
183 buffer_->
size() /
sizeof(T));
195 roc_panic(
"slice: out of bounds: available=[%lu,%lu) requested=%lu",
196 (
unsigned long)0, (
unsigned long)size_, (
unsigned long)
i);
Fixed-size dynamically-allocated byte buffer.
size_t size() const
Get buffer size in bytes.
uint8_t * data()
Get buffer data.
Shared ownership intrusive pointer.
Slice subslice(size_t from, size_t to) const
Construct a slice pointing to a part of this slice.
T * extend(const size_t add_sz)
Increase size() by add_sz.
size_t capacity() const
Get maximum possible number of elements in slice.
Slice(Buffer &buffer, size_t from, size_t to)
Construct slice pointing to a part of a buffer.
T * data_end() const
Pointer to the next after the last element in slice.
T & operator[](const size_t i) const
Access to an element of the Slice with an array style.
void reslice(size_t from, size_t to)
Change slice beginning and ending inside the buffer.
void print() const
Print slice to stderr.
Slice(const BufferPtr &buffer)
Construct slice pointing to the whole buffer.
T * data() const
Get slice data.
Slice()
Construct empty slice.
size_t size() const
Get number of elements in slice.
void print_memory_slice(const uint8_t *inner, size_t inner_size, const uint8_t *outer, size_t outer_size)
Print memory slice.
#define roc_panic(...)
Print error message and terminate program gracefully.
Shared ownership intrusive pointer.