2024-03-05 21:49:07 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 suyu Emulator Project
|
2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-10-27 04:07:36 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
enum class SeekOrigin {
|
|
|
|
SetOrigin,
|
|
|
|
FromCurrentPos,
|
|
|
|
FromEnd,
|
|
|
|
};
|
|
|
|
|
|
|
|
class Stream {
|
|
|
|
public:
|
|
|
|
/// Stream creates a bitstream and provides common functionality on the stream.
|
|
|
|
explicit Stream();
|
|
|
|
~Stream();
|
|
|
|
|
2020-10-30 03:55:56 +01:00
|
|
|
Stream(const Stream&) = delete;
|
|
|
|
Stream& operator=(const Stream&) = delete;
|
|
|
|
|
|
|
|
Stream(Stream&&) = default;
|
|
|
|
Stream& operator=(Stream&&) = default;
|
|
|
|
|
2020-10-27 04:07:36 +01:00
|
|
|
/// Reposition bitstream "cursor" to the specified offset from origin
|
|
|
|
void Seek(s32 offset, SeekOrigin origin);
|
|
|
|
|
|
|
|
/// Reads next byte in the stream buffer and increments position
|
|
|
|
u8 ReadByte();
|
|
|
|
|
|
|
|
/// Writes byte at current position
|
|
|
|
void WriteByte(u8 byte);
|
|
|
|
|
2020-10-30 03:55:56 +01:00
|
|
|
[[nodiscard]] std::size_t GetPosition() const {
|
2020-10-27 04:07:36 +01:00
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
2020-10-30 03:55:56 +01:00
|
|
|
[[nodiscard]] std::vector<u8>& GetBuffer() {
|
2020-10-27 04:07:36 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2020-10-30 03:55:56 +01:00
|
|
|
[[nodiscard]] const std::vector<u8>& GetBuffer() const {
|
2020-10-27 04:07:36 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<u8> buffer;
|
|
|
|
std::size_t position{0};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Common
|