libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
MemoryStream.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5#include "Stream.h"
6
7namespace Ship {
20class MemoryStream final : public Stream {
21 public:
24
34 MemoryStream(char* nBuffer, size_t nBufferSize);
35
40 MemoryStream(std::shared_ptr<std::vector<char>> buffer);
41
47 MemoryStream(std::shared_ptr<std::vector<char>> buffer, size_t offset);
49
53 uint64_t GetLength() override;
54
60 void Seek(int32_t offset, SeekOffsetType seekType) override;
61
67 std::unique_ptr<char[]> Read(size_t length) override;
68
74 void Read(char* dest, size_t length) override;
75
83 int8_t ReadByte() override;
84
94 void Write(char* srcBuffer, size_t length) override;
95
100 void WriteByte(int8_t value) override;
101
105 std::vector<char> ToVector() override;
106
108 void Flush() override;
109
111 void Close() override;
112
113 protected:
114 std::shared_ptr<std::vector<char>> mBuffer;
115 std::size_t mBufferSize;
116};
117} // namespace Ship
A Stream backed by an in-memory byte buffer.
Definition MemoryStream.h:20
std::size_t mBufferSize
Fixed size (0 if growable).
Definition MemoryStream.h:115
MemoryStream(std::shared_ptr< std::vector< char > > buffer)
Constructs a memory stream over a shared vector, positioned at the start.
void Read(char *dest, size_t length) override
Reads length bytes into dest from the current position.
uint64_t GetLength() override
Returns the total number of bytes in the backing buffer.
void Seek(int32_t offset, SeekOffsetType seekType) override
Moves the current position within the backing buffer.
std::shared_ptr< std::vector< char > > mBuffer
Shared backing store.
Definition MemoryStream.h:114
void WriteByte(int8_t value) override
Writes a single signed byte at the current position.
void Flush() override
No-op for in-memory streams; included for interface compliance.
MemoryStream(char *nBuffer, size_t nBufferSize)
Constructs a memory stream by copying a raw byte buffer.
std::vector< char > ToVector() override
Returns a copy of the entire backing buffer as a vector.
void Close() override
No-op for in-memory streams; the buffer remains valid after closing.
std::unique_ptr< char[]> Read(size_t length) override
Reads length bytes starting at the current position.
void Write(char *srcBuffer, size_t length) override
Writes length bytes from srcBuffer at the current position.
MemoryStream(std::shared_ptr< std::vector< char > > buffer, size_t offset)
Constructs a memory stream over a shared vector at a given byte offset.
int8_t ReadByte() override
Reads a single signed byte and advances the position by one.
MemoryStream()
Constructs an empty, growable memory stream.
Abstract base class for sequential byte streams (read/write).
Definition Stream.h:26
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
SeekOffsetType
Identifies the reference point for a seek operation.
Definition Stream.h:10