15class ReadOnlyStorageView :
public StorageBase<ReadOnlyStorageView> {
17 ReadOnlyStorageView() =
default;
36 std::size_t count_bytes)
const {
37 return SplitSpan(data_.subspan(offset_bytes, count_bytes));
41 ReadOnlyStorageView
view_impl(std::size_t offset_bytes,
42 std::size_t count_bytes)
const {
43 if (offset_bytes > data_.size() ||
44 count_bytes > data_.size() - offset_bytes) {
45 throw std::out_of_range(
"Storage view is outside the backing storage");
47 return ReadOnlyStorageView(data_.subspan(offset_bytes, count_bytes));
61 const std::size_t size = reader.
read_size();
62 return ReadOnlyStorageView(reader.
read_bytes(size));
66 std::span<const std::byte> data_;
Bounds-checked reader for canonical little-endian binary data.
Definition serialization.h:526
std::span< const std::byte > read_bytes(std::size_t count)
Read exactly count uninterpreted bytes.
Definition serialization.h:604
std::size_t read_size()
Read an unsigned 64-bit size and convert it to size_t.
Definition serialization.h:587
ReadOnlyStorageView(std::span< const std::byte > data)
Construct a view over data.
Definition read_only_view.h:20
SplitSpan< const std::byte > segments_impl(std::size_t offset_bytes, std::size_t count_bytes) const
Return a checked viewed byte range as one physical segment.
Definition read_only_view.h:35
ReadOnlyStorageView view_impl(std::size_t offset_bytes, std::size_t count_bytes) const
Return a checked read-only byte subrange.
Definition read_only_view.h:41
static ReadOnlyStorageView deserialize_impl(BinaryReader &reader)
Deserialize a size-prefixed view and advance reader.
Definition read_only_view.h:60
std::span< const std::byte > as_bytes_impl() const
Return the viewed bytes.
Definition read_only_view.h:32
position_type end_position_impl() const
Return the position one past the final logical byte.
Definition read_only_view.h:29
position_type begin_position_impl() const
Return the first logical byte position.
Definition read_only_view.h:26
std::size_t size_bytes_impl() const
Return the number of viewed bytes.
Definition read_only_view.h:23
A logical contiguous sequence stored in at most two physical spans.
Definition split_span.h:25
CRTP facade for byte-addressable storage.
Definition storage.h:65
std::uint64_t position_type
Definition storage.h:68
Common interface for byte-addressable storage.