57 if (data_ ==
nullptr) {
74 template<
typename T = Type, std::enable_if_t<!std::is_const_v<T>,
int> = 0>
81 template<
typename T = Type, std::enable_if_t<!std::is_const_v<T>,
int> = 0>
95 [[nodiscard]]
const Type*
data()
const {
109 [[nodiscard]]
size_t size()
const {
117 return size_ *
sizeof(Type);
134 template<
typename ValueType, std::enable_if_t<std::is_trivially_copyable_v<ValueType>,
bool> = true>
135 ValueType
read_ne(
const size_t offset)
const {
146 template<
typename ValueType, std::enable_if_t<std::is_trivially_copyable_v<ValueType>,
bool> = true>
147 ValueType
read_be(
const size_t offset)
const {
157 template<
typename ValueType, std::enable_if_t<std::is_trivially_copyable_v<ValueType>,
bool> = true>
158 ValueType
read_le(
const size_t offset)
const {
167 offset = std::min(offset, size_);
168 return BufferView(data_ + offset, size_ - offset);
177 offset = std::min(offset, size_);
178 return BufferView(data_ + offset, std::min(size_ - offset,
size));
194 template<
class NewType>
196 return BufferView<NewType>(
reinterpret_cast<NewType*
>(data_), size_ *
sizeof(Type) /
sizeof(NewType));
200 Type* data_ {
nullptr};
#define RAV_ASSERT(condition, message)
Asserts condition to be true, otherwise:
size_t size_bytes() const
ValueType read_ne(const size_t offset) const
Reads a value from the data in native byte order (not to be confused with network-endian).
BufferView< NewType > reinterpret() const
Returns a new buffer_view pointing to the same data, but reinterpreted as a different type.
BufferView & operator=(BufferView &&other) noexcept=default
BufferView< std::add_const_t< Type > > const_view() const
ValueType read_be(const size_t offset) const
Reads a big-endian value from the given data.
BufferView subview(size_t offset) const
BufferView(BufferView &&other) noexcept=default
BufferView(Type *data, const size_t size)
Construct a view pointing to given data.
BufferView(const std::vector< Type > &vector)
Construct a view from a std::vector.
Type & operator[](size_t index) const
BufferView(std::vector< Type > &vector)
Construct a view from a std::vector.
BufferView(const std::array< Type, S > &array)
Construct a view from a std::array.
const Type * data() const
ValueType read_le(const size_t offset) const
Reads a little-endian value from the given data.
BufferView(const BufferView &other)=default
BufferView subview(size_t offset, const size_t size) const
BufferView & operator=(const BufferView &other)=default
Type swap_if_le(const Type value)
Swaps the bytes of the given value if the system is little-endian.
Type read_ne(const uint8_t *data)
Reads a value from the given data in native byte order (not to be confused with network-endian).
Type swap_if_be(const Type value)
Swaps the bytes of the given value if the system is big-endian.