ezEngine Release 26.3
Loading...
Searching...
No Matches
ezStreamWriter Class Referenceabstract

Abstract base class for binary output streams providing unified writing interface. More...

#include <Stream.h>

Inheritance diagram for ezStreamWriter:

Public Member Functions

 ezStreamWriter ()
 Constructor.
 
virtual ~ezStreamWriter ()
 Virtual destructor to ensure correct cleanup.
 
virtual ezResult WriteBytes (const void *pWriteBuffer, ezUInt64 uiBytesToWrite)=0
 Writes a raw number of bytes from the buffer. This is the only method that must be implemented by derived classes.
 
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

Abstract base class for binary output streams providing unified writing interface.

StreamWriter defines the fundamental interface for writing binary data to various destinations including files, memory buffers, network connections, and compressed streams. All write operations are performed sequentially with automatic endianness handling.

Core functionality:

  • WriteBytes(): Raw binary data writing (pure virtual, must be implemented)
  • Typed writing methods with endianness conversion (WriteWordValue, WriteDWordValue, etc.)
  • High-level container writing (arrays, sets, maps, hash tables)
  • String writing with automatic length prefixing
  • Optional flush support for ensuring data persistence

Implementation requirements:

  • Derived classes must implement WriteBytes() as the primary write method
  • All other methods are implemented in terms of WriteBytes()
  • Flush() can be overridden for buffered implementations
  • Should handle write errors gracefully by returning appropriate ezResult

Member Function Documentation

◆ Flush()

virtual ezResult ezStreamWriter::Flush ( )
inlinevirtual

Flushes buffered data to the underlying storage, ensuring data persistence.

Default implementation is a no-op. Derived classes with internal buffering should override this method to force writing of buffered data to the actual destination.

Reimplemented in ezFileWriter, and ezStreamWriterWithStats.

◆ WriteBytes()

virtual ezResult ezStreamWriter::WriteBytes ( const void *  pWriteBuffer,
ezUInt64  uiBytesToWrite 
)
pure virtual

Writes a raw number of bytes from the buffer. This is the only method that must be implemented by derived classes.

Parameters
pWriteBufferSource buffer containing data to write
uiBytesToWriteNumber of bytes to write from the buffer
Returns
EZ_SUCCESS if all bytes were written successfully, EZ_FAILURE otherwise

Implemented in ezHashStreamWriter32, ezHashStreamWriter64, ezChunkStreamWriter, ezDeferredFileWriter, ezFileWriter, ezMemoryStreamWriter, ezRawMemoryStreamWriter, and ezStreamWriterWithStats.


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