Minecraft Community Edition 0.1.0
Loading...
Searching...
No Matches
mce::MemoryInputStream Class Referencefinal

Memory-backed input stream. More...

#include <MemoryInputStream.hpp>

Inheritance diagram for mce::MemoryInputStream:
mce::InputStream

Public Member Functions

 MemoryInputStream (const void *data, size_t size)
 Construct a memory input stream over existing data.
virtual size_t read (void *buffer, size_t size) override
 Read bytes from the memory buffer into the provided buffer.
size_t readString (char *&buffer, size_t &size)
 Read a NUL-terminated string from the stream.
virtual size_t seek (size_t position) override
 Seek to an absolute position in the memory buffer.
virtual size_t tell () override
 Get the current read position in the buffer.
virtual size_t getSize () override
 Get the total size of the memory buffer.

Detailed Description

Memory-backed input stream.

Provides a read-only InputStream view over an existing memory buffer. The stream does not take ownership of the provided memory; the caller is responsible for ensuring the lifetime of the memory buffer exceeds the lifetime of the MemoryInputStream instance.

Constructor & Destructor Documentation

◆ MemoryInputStream()

mce::MemoryInputStream::MemoryInputStream ( const void * data,
size_t size )

Construct a memory input stream over existing data.

Parameters
dataPointer to the memory buffer to read from. Must not be nullptr unless size is zero.
sizeSize of the buffer in bytes.

Member Function Documentation

◆ getSize()

size_t mce::MemoryInputStream::getSize ( )
overridevirtual

Get the total size of the memory buffer.

Returns
Size of the buffer in bytes.

Implements mce::InputStream.

◆ read()

size_t mce::MemoryInputStream::read ( void * buffer,
size_t size )
overridevirtual

Read bytes from the memory buffer into the provided buffer.

Parameters
bufferDestination buffer to receive data.
sizeMaximum number of bytes to read from the stream.
Returns
Number of bytes actually read.

Implements mce::InputStream.

◆ readString()

size_t mce::MemoryInputStream::readString ( char *& buffer,
size_t & size )

Read a NUL-terminated string from the stream.

The function does not allocate new memory for the string. Instead it returns a pointer into the original memory buffer via the buffer reference parameter. The returned pointer is valid only while the original memory and this stream remain valid.

Parameters
bufferReference to a char* which will be set to point to the string inside the memory buffer.
sizeReference to a size_t which will be set to the length of the string (excluding the terminating NUL).
Returns
Number of bytes consumed from the stream, including the terminating NULL byte.

◆ seek()

size_t mce::MemoryInputStream::seek ( size_t position)
overridevirtual

Seek to an absolute position in the memory buffer.

Parameters
positionAbsolute position in bytes from the start of the buffer.
Returns
The new position after seeking.

Implements mce::InputStream.

◆ tell()

size_t mce::MemoryInputStream::tell ( )
overridevirtual

Get the current read position in the buffer.

Returns
Current position in bytes from the start of the buffer.

Implements mce::InputStream.


The documentation for this class was generated from the following files: