summaryrefslogtreecommitdiff
path: root/src/common/stream.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/stream.h')
-rw-r--r--src/common/stream.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/common/stream.h b/src/common/stream.h
new file mode 100644
index 000000000..0e40692de
--- /dev/null
+++ b/src/common/stream.h
@@ -0,0 +1,56 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <vector>
8#include "common/common_types.h"
9
10namespace Common {
11
12enum class SeekOrigin {
13 SetOrigin,
14 FromCurrentPos,
15 FromEnd,
16};
17
18class Stream {
19public:
20 /// Stream creates a bitstream and provides common functionality on the stream.
21 explicit Stream();
22 ~Stream();
23
24 Stream(const Stream&) = delete;
25 Stream& operator=(const Stream&) = delete;
26
27 Stream(Stream&&) = default;
28 Stream& operator=(Stream&&) = default;
29
30 /// Reposition bitstream "cursor" to the specified offset from origin
31 void Seek(s32 offset, SeekOrigin origin);
32
33 /// Reads next byte in the stream buffer and increments position
34 u8 ReadByte();
35
36 /// Writes byte at current position
37 void WriteByte(u8 byte);
38
39 [[nodiscard]] std::size_t GetPosition() const {
40 return position;
41 }
42
43 [[nodiscard]] std::vector<u8>& GetBuffer() {
44 return buffer;
45 }
46
47 [[nodiscard]] const std::vector<u8>& GetBuffer() const {
48 return buffer;
49 }
50
51private:
52 std::vector<u8> buffer;
53 std::size_t position{0};
54};
55
56} // namespace Common