@@ -41,27 +41,27 @@ namespace SatisfactorySave {
4141 virtual void write (std::span<const std::byte> in) = 0;
4242 };
4343
44- class SATISFACTORYSAVE_API MemoryIStream : public IStream {
44+ class SATISFACTORYSAVE_API MemoryViewIStream : public IStream {
4545 public:
46- explicit MemoryIStream (std::span<const std::byte> buffer) : buffer_(buffer), pos_(0 ) {}
46+ explicit MemoryViewIStream (std::span<const std::byte> buffer) : buffer_(buffer), pos_(0 ) {}
4747
4848 [[nodiscard]] pos_type tell () const override {
4949 return pos_;
5050 }
5151
5252 void seek (pos_type pos) override {
5353 if (pos > buffer_.size ()) {
54- throw std::out_of_range (" MemoryIStream : Seek out of range." );
54+ throw std::out_of_range (" MemoryViewIStream : Seek out of range." );
5555 }
5656 pos_ = pos;
5757 }
5858
5959 void seek_relative (off_type off) override {
6060 if (off < 0 && static_cast <pos_type>(-off) > pos_) {
61- throw std::out_of_range (" MemoryIStream : Seek out of range." );
61+ throw std::out_of_range (" MemoryViewIStream : Seek out of range." );
6262 }
6363 if (off > 0 && pos_ + off > buffer_.size ()) {
64- throw std::out_of_range (" MemoryIStream : Seek out of range." );
64+ throw std::out_of_range (" MemoryViewIStream : Seek out of range." );
6565 }
6666 pos_ += off;
6767 }
@@ -72,17 +72,31 @@ namespace SatisfactorySave {
7272
7373 void read (std::span<std::byte> out) override {
7474 if (pos_ + out.size () > buffer_.size ()) {
75- throw std::runtime_error (" MemoryIStream : Not enough data to read." );
75+ throw std::runtime_error (" MemoryViewIStream : Not enough data to read." );
7676 }
7777 std::memcpy (out.data (), buffer_.data () + pos_, out.size ());
7878 pos_ += out.size ();
7979 }
8080
81- private:
81+ protected:
82+ MemoryViewIStream () : pos_(0 ) {}
83+
8284 std::span<const std::byte> buffer_;
8385 pos_type pos_;
8486 };
8587
88+ class MemoryBufferIStream : public MemoryViewIStream {
89+ public:
90+ explicit MemoryBufferIStream (std::vector<char >&& buffer)
91+ : MemoryViewIStream(),
92+ buffer_data_(std::move(buffer)) {
93+ buffer_ = std::as_bytes (std::span (buffer_data_));
94+ }
95+
96+ private:
97+ std::vector<char > buffer_data_;
98+ };
99+
86100 class SATISFACTORYSAVE_API MemoryOStream : public OStream {
87101 public:
88102 MemoryOStream () : content_size_(0 ), pos_(0 ) {}
0 commit comments