|
Minecraft Community Edition 0.1.0
|
Memory-backed input stream. More...
#include <MemoryInputStream.hpp>
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. | |
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.
| mce::MemoryInputStream::MemoryInputStream | ( | const void * | data, |
| size_t | size ) |
Construct a memory input stream over existing data.
| data | Pointer to the memory buffer to read from. Must not be nullptr unless size is zero. |
| size | Size of the buffer in bytes. |
|
overridevirtual |
Get the total size of the memory buffer.
Implements mce::InputStream.
|
overridevirtual |
Read bytes from the memory buffer into the provided buffer.
| buffer | Destination buffer to receive data. |
| size | Maximum number of bytes to read from the stream. |
Implements mce::InputStream.
| 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.
| 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). |
|
overridevirtual |
Seek to an absolute position in the memory buffer.
| position | Absolute position in bytes from the start of the buffer. |
Implements mce::InputStream.
|
overridevirtual |
Get the current read position in the buffer.
Implements mce::InputStream.