stream.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <vector>
  5. #include "common/common_types.h"
  6. namespace Common {
  7. enum class SeekOrigin {
  8. SetOrigin,
  9. FromCurrentPos,
  10. FromEnd,
  11. };
  12. class Stream {
  13. public:
  14. /// Stream creates a bitstream and provides common functionality on the stream.
  15. explicit Stream();
  16. ~Stream();
  17. Stream(const Stream&) = delete;
  18. Stream& operator=(const Stream&) = delete;
  19. Stream(Stream&&) = default;
  20. Stream& operator=(Stream&&) = default;
  21. /// Reposition bitstream "cursor" to the specified offset from origin
  22. void Seek(s32 offset, SeekOrigin origin);
  23. /// Reads next byte in the stream buffer and increments position
  24. u8 ReadByte();
  25. /// Writes byte at current position
  26. void WriteByte(u8 byte);
  27. [[nodiscard]] std::size_t GetPosition() const {
  28. return position;
  29. }
  30. [[nodiscard]] std::vector<u8>& GetBuffer() {
  31. return buffer;
  32. }
  33. [[nodiscard]] const std::vector<u8>& GetBuffer() const {
  34. return buffer;
  35. }
  36. private:
  37. std::vector<u8> buffer;
  38. std::size_t position{0};
  39. };
  40. } // namespace Common