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 
10 namespace Common {
11 
12 enum class SeekOrigin {
13     SetOrigin,
14     FromCurrentPos,
15     FromEnd,
16 };
17 
18 class Stream {
19 public:
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 
GetPosition()39     [[nodiscard]] std::size_t GetPosition() const {
40         return position;
41     }
42 
GetBuffer()43     [[nodiscard]] std::vector<u8>& GetBuffer() {
44         return buffer;
45     }
46 
GetBuffer()47     [[nodiscard]] const std::vector<u8>& GetBuffer() const {
48         return buffer;
49     }
50 
51 private:
52     std::vector<u8> buffer;
53     std::size_t position{0};
54 };
55 
56 } // namespace Common
57