stream.h 1.2 KB

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