A Stream backed by an in-memory byte buffer.
More...
#include <MemoryStream.h>
|
| | MemoryStream () |
| | Constructs an empty, growable memory stream.
|
| |
| | MemoryStream (char *nBuffer, size_t nBufferSize) |
| | Constructs a memory stream by copying a raw byte buffer.
|
| |
| | MemoryStream (std::shared_ptr< std::vector< char > > buffer) |
| | Constructs a memory stream over a shared vector, positioned at the start.
|
| |
| | MemoryStream (std::shared_ptr< std::vector< char > > buffer, size_t offset) |
| | Constructs a memory stream over a shared vector at a given byte offset.
|
| |
| | ~MemoryStream () |
| |
| 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::unique_ptr< char[]> | Read (size_t length) override |
| | Reads length bytes starting at the current position.
|
| |
| void | Read (char *dest, size_t length) override |
| | Reads length bytes into dest from the current position.
|
| |
| int8_t | ReadByte () override |
| | Reads a single signed byte and advances the position by one.
|
| |
| void | Write (char *srcBuffer, size_t length) override |
| | Writes length bytes from srcBuffer at the current position.
|
| |
| void | WriteByte (int8_t value) override |
| | Writes a single signed byte at the current position.
|
| |
| std::vector< char > | ToVector () override |
| | Returns a copy of the entire backing buffer as a vector.
|
| |
| void | Flush () override |
| | No-op for in-memory streams; included for interface compliance.
|
| |
| void | Close () override |
| | No-op for in-memory streams; the buffer remains valid after closing.
|
| |
| virtual | ~Stream ()=default |
| |
| uint64_t | GetBaseAddress () |
| | Returns the current stream position as an absolute byte offset.
|
| |
|
| std::shared_ptr< std::vector< char > > | mBuffer |
| | Shared backing store.
|
| |
| std::size_t | mBufferSize |
| | Fixed size (0 if growable).
|
| |
| uint64_t | mBaseAddress |
| | Current read/write position (byte offset from the start).
|
| |
A Stream backed by an in-memory byte buffer.
MemoryStream can be constructed from an existing raw buffer, from a shared vector (with an optional initial seek offset), or as an empty growable buffer. It is the concrete stream type used by BinaryReader and BinaryWriter throughout the archive and resource serialisation pipeline.
All operations are performed in-process; no I/O is involved. The internal buffer is managed via a shared_ptr<vector<char>> so that multiple owners can safely share the same underlying storage.
◆ MemoryStream() [1/4]
| Ship::MemoryStream::MemoryStream |
( |
| ) |
|
Constructs an empty, growable memory stream.
◆ MemoryStream() [2/4]
| Ship::MemoryStream::MemoryStream |
( |
char * |
nBuffer, |
|
|
size_t |
nBufferSize |
|
) |
| |
Constructs a memory stream by copying a raw byte buffer.
The contents of the buffer are copied into an internal vector, so the caller is free to release the original buffer after construction.
- Parameters
-
| nBuffer | Pointer to the raw byte buffer to copy. |
| nBufferSize | Size of the buffer in bytes. |
◆ MemoryStream() [3/4]
| Ship::MemoryStream::MemoryStream |
( |
std::shared_ptr< std::vector< char > > |
buffer | ) |
|
Constructs a memory stream over a shared vector, positioned at the start.
- Parameters
-
| buffer | Shared vector to use as the backing store. |
◆ MemoryStream() [4/4]
| Ship::MemoryStream::MemoryStream |
( |
std::shared_ptr< std::vector< char > > |
buffer, |
|
|
size_t |
offset |
|
) |
| |
Constructs a memory stream over a shared vector at a given byte offset.
- Parameters
-
| buffer | Shared vector to use as the backing store. |
| offset | Initial seek position (byte offset from the beginning of buffer). |
◆ ~MemoryStream()
| Ship::MemoryStream::~MemoryStream |
( |
| ) |
|
◆ Close()
| void Ship::MemoryStream::Close |
( |
| ) |
|
|
overridevirtual |
No-op for in-memory streams; the buffer remains valid after closing.
Implements Ship::Stream.
◆ Flush()
| void Ship::MemoryStream::Flush |
( |
| ) |
|
|
overridevirtual |
No-op for in-memory streams; included for interface compliance.
Implements Ship::Stream.
◆ GetLength()
| uint64_t Ship::MemoryStream::GetLength |
( |
| ) |
|
|
overridevirtual |
Returns the total number of bytes in the backing buffer.
Implements Ship::Stream.
◆ Read() [1/2]
| void Ship::MemoryStream::Read |
( |
char * |
dest, |
|
|
size_t |
length |
|
) |
| |
|
overridevirtual |
Reads length bytes into dest from the current position.
- Parameters
-
| dest | Writable destination buffer (must be at least length bytes). |
| length | Number of bytes to read. |
Implements Ship::Stream.
◆ Read() [2/2]
| std::unique_ptr< char[]> Ship::MemoryStream::Read |
( |
size_t |
length | ) |
|
|
overridevirtual |
Reads length bytes starting at the current position.
- Parameters
-
| length | Number of bytes to read. |
- Returns
- Heap-allocated buffer containing the copied bytes.
Implements Ship::Stream.
◆ ReadByte()
| int8_t Ship::MemoryStream::ReadByte |
( |
| ) |
|
|
overridevirtual |
Reads a single signed byte and advances the position by one.
Throws std::out_of_range if the position is past the end of the buffer.
- Returns
- The byte value at the current position.
Implements Ship::Stream.
◆ Seek()
| void Ship::MemoryStream::Seek |
( |
int32_t |
offset, |
|
|
SeekOffsetType |
seekType |
|
) |
| |
|
overridevirtual |
Moves the current position within the backing buffer.
- Parameters
-
| offset | Byte offset (can be negative for SeekOffsetType::Current and End). |
| seekType | Reference point (Start, Current, or End). |
Implements Ship::Stream.
◆ ToVector()
| std::vector< char > Ship::MemoryStream::ToVector |
( |
| ) |
|
|
overridevirtual |
Returns a copy of the entire backing buffer as a vector.
Implements Ship::Stream.
◆ Write()
| void Ship::MemoryStream::Write |
( |
char * |
srcBuffer, |
|
|
size_t |
length |
|
) |
| |
|
overridevirtual |
Writes length bytes from srcBuffer at the current position.
If the stream was constructed as growable (no fixed size), the backing vector is extended as needed.
- Parameters
-
| srcBuffer | Source buffer. |
| length | Number of bytes to write. |
Implements Ship::Stream.
◆ WriteByte()
| void Ship::MemoryStream::WriteByte |
( |
int8_t |
value | ) |
|
|
overridevirtual |
Writes a single signed byte at the current position.
- Parameters
-
Implements Ship::Stream.
◆ mBuffer
| std::shared_ptr<std::vector<char> > Ship::MemoryStream::mBuffer |
|
protected |
◆ mBufferSize
| std::size_t Ship::MemoryStream::mBufferSize |
|
protected |
Fixed size (0 if growable).
The documentation for this class was generated from the following file: