ezEngine Release 26.3
Loading...
Searching...
No Matches
ezChunkStreamWriter Class Reference

Stream writer that organizes data into named, versioned chunks. More...

#include <ChunkStream.h>

Inheritance diagram for ezChunkStreamWriter:

Public Member Functions

 ezChunkStreamWriter (ezStreamWriter &inout_stream)
 Pass the underlying stream writer to the constructor.
 
virtual ezResult WriteBytes (const void *pWriteBuffer, ezUInt64 uiBytesToWrite) override
 Writes bytes directly to the stream. Only allowed when a chunk is open (between BeginChunk / EndChunk).
 
virtual void BeginStream (ezUInt16 uiVersion)
 Initializes the chunk stream with a format version.
 
virtual void EndStream ()
 Stops writing to the chunk file. Has to be the last thing that is called.
 
virtual void BeginChunk (ezStringView sName, ezUInt32 uiVersion)
 Begins a new named chunk with its own version.
 
virtual void EndChunk ()
 Closes the current chunk.
 
- Public Member Functions inherited from ezStreamWriter
 ezStreamWriter ()
 Constructor.
 
virtual ~ezStreamWriter ()
 Virtual destructor to ensure correct cleanup.
 
virtual ezResult Flush ()
 Flushes buffered data to the underlying storage, ensuring data persistence.
 
template<typename T >
ezResult WriteWordValue (const T *pWordValue)
 Helper method to write a word value correctly (copes with potentially different endianess)
 
template<typename T >
ezResult WriteDWordValue (const T *pDWordValue)
 Helper method to write a dword value correctly (copes with potentially different endianess)
 
template<typename T >
ezResult WriteQWordValue (const T *pQWordValue)
 Helper method to write a qword value correctly (copes with potentially different endianess)
 
EZ_ALWAYS_INLINE void WriteVersion (ezTypeVersion version)
 Writes a type version to the stream.
 
template<typename ArrayType , typename ValueType >
ezResult WriteArray (const ezArrayBase< ValueType, ArrayType > &array)
 Writes an array of elements to the stream.
 
template<typename ValueType , ezUInt16 uiSize>
ezResult WriteArray (const ezSmallArrayBase< ValueType, uiSize > &array)
 Writes a small array of elements to the stream.
 
template<typename ValueType , ezUInt32 uiSize>
ezResult WriteArray (const ValueType(&array)[uiSize])
 Writes a C style fixed array.
 
template<typename KeyType , typename Comparer >
ezResult WriteSet (const ezSetBase< KeyType, Comparer > &set)
 Writes a set.
 
template<typename KeyType , typename ValueType , typename Comparer >
ezResult WriteMap (const ezMapBase< KeyType, ValueType, Comparer > &map)
 Writes a map.
 
template<typename KeyType , typename ValueType , typename Hasher >
ezResult WriteHashTable (const ezHashTableBase< KeyType, ValueType, Hasher > &hashTable)
 Writes a hash table (note that the entry order might change on read)
 
ezResult WriteString (const ezStringView sStringView)
 Writes a string.
 

Detailed Description

Stream writer that organizes data into named, versioned chunks.

This stream writer subdivides data into discrete chunks, each with a name, version, and byte size. Chunks act like logical sub-streams within a single stream, enabling structured data storage where different parts can be versioned independently. The chunk format includes headers with metadata, making it suitable for file formats that need backward compatibility or selective reading. Use BeginStream/EndStream to wrap the entire operation and BeginChunk/EndChunk for individual chunks.

Member Function Documentation

◆ BeginChunk()

void ezChunkStreamWriter::BeginChunk ( ezStringView  sName,
ezUInt32  uiVersion 
)
virtual

Begins a new named chunk with its own version.

Chunks cannot be nested (use multiple chunk writers for nested structures). The chunk name and version are written to the header for identification and compatibility.

◆ BeginStream()

void ezChunkStreamWriter::BeginStream ( ezUInt16  uiVersion)
virtual

Initializes the chunk stream with a format version.

Must be called first before writing any chunks. The version number is stored in the stream header and can be retrieved by ezChunkStreamReader::BeginStream() for format compatibility checks.

◆ EndChunk()

void ezChunkStreamWriter::EndChunk ( )
virtual

Closes the current chunk.

Todo:
Write Chunk CRC

◆ WriteBytes()

ezResult ezChunkStreamWriter::WriteBytes ( const void *  pWriteBuffer,
ezUInt64  uiBytesToWrite 
)
overridevirtual

Writes bytes directly to the stream. Only allowed when a chunk is open (between BeginChunk / EndChunk).

Implements ezStreamWriter.


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