wren
Vulkan-based game engine
Loading...
Searching...
No Matches
binary_reader.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <span>
4
5namespace wren::utils {
6
8 public:
9 BinaryReader(const std::span<const std::byte>& data)
10 : data_(data), pos_(data_.begin()) {}
11
12 void skip(size_t byte_count) { pos_ += static_cast<long>(byte_count); }
13
14 template <typename T>
15 auto read() {
16 std::span sub(pos_, pos_ + sizeof(T));
17 pos_ += sizeof(T);
18
19 return *reinterpret_cast<const T*>(sub.data());
20 }
21
22 template <typename T, std::size_t N>
23 auto read_list() {
24 std::array<T, N> list;
25
26 for (auto i = 0; i < N; ++i) {
27 list.at(i) = read<T>();
28 }
29
30 return list;
31 }
32
33 auto at_end() { return pos_ == data_.end(); }
34
35 private:
36 std::span<const std::byte> data_;
37 std::span<const std::byte>::iterator pos_;
38};
39
40} // namespace wren::utils
std::span< const std::byte > data_
Definition binary_reader.hpp:36
auto read_list()
Definition binary_reader.hpp:23
void skip(size_t byte_count)
Definition binary_reader.hpp:12
auto read()
Definition binary_reader.hpp:15
std::span< conststd::byte >::iterator pos_
Definition binary_reader.hpp:37
auto at_end()
Definition binary_reader.hpp:33
BinaryReader(const std::span< const std::byte > &data)
Definition binary_reader.hpp:9
Definition binary_reader.hpp:5