Loading...
Searching...
No Matches
mce::MemoryInputStream Class Referencefinal

Memory-backed input stream. More...

`#include <MemoryInputStream.hpp>`

Inheritance diagram for mce::MemoryInputStream:

## 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

  data | Pointer to the memory buffer to read from. Must not be nullptr unless size is zero.
  size | Size 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

  buffer | Destination buffer to receive data.
  size | Maximum 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

  buffer | Reference to a char* which will be set to point to the string inside the memory buffer.
  size | Reference 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

  position | Absolute 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:

- IO/Stream/MemoryInputStream.hpp
- IO/Stream/MemoryInputStream.cpp