42 lines
1.0 KiB
C++
Raw Normal View History

2025-02-20 05:32:33 -05:00
// Copyright 2025 xensik. All rights reserved.
2024-02-27 01:34:37 -05:00
//
// Use of this source code is governed by a GNU GPLv3 license
// that can be found in the LICENSE file.
#pragma once
namespace xsk::utils
{
2025-02-20 05:32:33 -05:00
struct reader
2024-02-27 01:34:37 -05:00
{
using ptr = std::unique_ptr<reader>;
2025-02-20 05:32:33 -05:00
using error = std::runtime_error;
2024-02-27 01:34:37 -05:00
private:
u8 const* data_;
2025-02-20 05:32:33 -05:00
usize size_;
usize pos_ = 0;
2024-02-27 01:34:37 -05:00
bool swap_;
public:
2025-02-20 05:32:33 -05:00
explicit reader(bool swap = false);
2024-02-27 01:34:37 -05:00
reader(std::vector<u8> const& data, bool swap = false);
2025-02-20 05:32:33 -05:00
reader(u8 const* data, usize size, bool swap = false);
2024-02-27 01:34:37 -05:00
template <typename T>
auto read() -> T;
2025-02-20 05:32:33 -05:00
auto read_i24() -> i32;
2024-02-27 01:34:37 -05:00
auto read_cstr() -> std::string;
2025-02-20 05:32:33 -05:00
auto read_bytes(usize pos, usize count) const -> std::string;
auto is_avail() const -> bool;
auto seek(usize size) -> void;
auto seek_neg(usize size) -> void;
auto align(usize size) -> usize;
auto data() const -> u8 const*;
auto size() const -> usize;
auto pos() const -> usize;
auto pos(usize pos) -> void;
2024-02-27 01:34:37 -05:00
};
} // namespace xsk::utils