wren
Vulkan-based game engine
Loading...
Searching...
No Matches
binray_reader.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <span>
5
6namespace wren::utils {
7
9 public:
10 BinaryReader(std::span<uint8_t>& data) : 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<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 private:
34 std::span<uint8_t> data_;
35 std::span<uint8_t>::iterator pos_;
36};
37
38} // namespace wren::utils
Definition binray_reader.hpp:8
auto read_list()
Definition binray_reader.hpp:23
std::span< uint8_t > data_
Definition binray_reader.hpp:34
void skip(size_t byte_count)
Definition binray_reader.hpp:12
auto read()
Definition binray_reader.hpp:15
std::span< uint8_t >::iterator pos_
Definition binray_reader.hpp:35
BinaryReader(std::span< uint8_t > &data)
Definition binray_reader.hpp:10
Definition binray_reader.hpp:6