Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::ByteStream Class Reference

Core class that represents a stream of bytes. More...

Inheritance diagram for Nz::ByteStream:
Nz::NetPacket

Public Member Functions

 ByteStream (Stream *stream=nullptr)
 Constructs a ByteStream object with a stream.
 
 ByteStream (ByteArray *byteArray, OpenModeFlags openMode=OpenMode_ReadWrite)
 Constructs a ByteStream object with a byte array. More...
 
 ByteStream (void *ptr, Nz::UInt64 size)
 Constructs a ByteStream object with a raw memory and a size. More...
 
 ByteStream (const void *ptr, Nz::UInt64 size)
 Constructs a ByteStream object with a raw memory and a size. More...
 
 ByteStream (const ByteStream &)=delete
 
 ByteStream (ByteStream &&stream)
 Constructs a ByteStream object by move semantic. More...
 
virtual ~ByteStream ()
 Destructs the object and calls FlushBits. More...
 
Endianness GetDataEndianness () const
 Gets the stream endianness. More...
 
Nz::UInt64 GetSize () const
 Gets the size of the byte stream. More...
 
StreamGetStream () const
 Gets the internal stream. More...
 
bool FlushBits ()
 Flushes the stream. More...
 
std::size_t Read (void *ptr, std::size_t size)
 Reads data. More...
 
void SetDataEndianness (Endianness endiannes)
 Sets the stream endianness. More...
 
void SetStream (Stream *stream)
 Sets this with a stream. More...
 
void SetStream (ByteArray *byteArray, OpenModeFlags openMode=OpenMode_ReadWrite)
 Sets this with a byte array. More...
 
void SetStream (void *ptr, Nz::UInt64 size)
 Sets this with a raw memory and a size. More...
 
void SetStream (const void *ptr, Nz::UInt64 size)
 Sets this with a raw memory and a size. More...
 
void Write (const void *data, std::size_t size)
 Writes data. More...
 
template<typename T >
ByteStreamoperator>> (T &value)
 Outputs a data from the stream. More...
 
template<typename T >
ByteStreamoperator<< (const T &value)
 Adds the data to the stream. More...
 
ByteStreamoperator= (const ByteStream &)=delete
 
ByteStreamoperator= (ByteStream &&)
 Moves the other byte stream into this. More...
 

Detailed Description

Core class that represents a stream of bytes.

Constructor & Destructor Documentation

◆ ByteStream() [1/4]

Nz::ByteStream::ByteStream ( ByteArray byteArray,
OpenModeFlags  openMode = OpenMode_ReadWrite 
)

Constructs a ByteStream object with a byte array.

Parameters
byteArrayBytes to stream
openModeReading/writing mode for the stream

◆ ByteStream() [2/4]

Nz::ByteStream::ByteStream ( void *  ptr,
Nz::UInt64  size 
)

Constructs a ByteStream object with a raw memory and a size.

Parameters
ptrPointer to raw memory
sizeSize that can be read
Remarks
If preallocated space of ptr is less than the size, the behaviour is undefined

◆ ByteStream() [3/4]

Nz::ByteStream::ByteStream ( const void *  ptr,
Nz::UInt64  size 
)

Constructs a ByteStream object with a raw memory and a size.

Parameters
ptrConstant pointer to raw memory
sizeSize that can be read
Remarks
If preallocated space of ptr is less than the size, the behaviour is undefined

◆ ByteStream() [4/4]

Nz::ByteStream::ByteStream ( ByteStream &&  stream)
inline

Constructs a ByteStream object by move semantic.

Parameters
streamByteStream to move into this

◆ ~ByteStream()

Nz::ByteStream::~ByteStream ( )
inlinevirtual

Destructs the object and calls FlushBits.

Remarks
Produces a NazaraWarning if flush did not work
See also
FlushBits

Member Function Documentation

◆ FlushBits()

bool Nz::ByteStream::FlushBits ( )
inline

Flushes the stream.

Returns
true if flushing is successful

◆ GetDataEndianness()

Endianness Nz::ByteStream::GetDataEndianness ( ) const
inline

Gets the stream endianness.

Returns
Type of the endianness

◆ GetSize()

Nz::UInt64 Nz::ByteStream::GetSize ( ) const
inline

Gets the size of the byte stream.

Returns
Size of the stream

◆ GetStream()

Stream * Nz::ByteStream::GetStream ( ) const
inline

Gets the internal stream.

Returns
Internal stream

◆ operator<<()

template<typename T >
ByteStream & Nz::ByteStream::operator<< ( const T &  value)

Adds the data to the stream.

Returns
A reference to this
Parameters
valueValue to serialize
Remarks
Produces a NazaraError if serialization failed

◆ operator=()

ByteStream & Nz::ByteStream::operator= ( ByteStream &&  stream)
inline

Moves the other byte stream into this.

Returns
A reference to this
Parameters
streamByteStream to move in this

◆ operator>>()

template<typename T >
ByteStream & Nz::ByteStream::operator>> ( T &  value)

Outputs a data from the stream.

Returns
A reference to this
Parameters
valueValue to unserialize
Remarks
Produces a NazaraError if unserialization failed

◆ Read()

std::size_t Nz::ByteStream::Read ( void *  ptr,
std::size_t  size 
)
inline

Reads data.

Returns
Number of data read
Parameters
bufferPreallocated buffer to contain information read
sizeSize of the read and thus of the buffer

◆ SetDataEndianness()

void Nz::ByteStream::SetDataEndianness ( Endianness  endiannes)
inline

Sets the stream endianness.

Parameters
Typeof the endianness

◆ SetStream() [1/4]

void Nz::ByteStream::SetStream ( Stream stream)
inline

Sets this with a stream.

Parameters
streamStream existing
Remarks
Produces a NazaraAssert if stream is invalid

◆ SetStream() [2/4]

void Nz::ByteStream::SetStream ( ByteArray byteArray,
OpenModeFlags  openMode = OpenMode_ReadWrite 
)

Sets this with a byte array.

Parameters
byteArrayBytes to stream
openModeReading/writing mode for the stream

◆ SetStream() [3/4]

void Nz::ByteStream::SetStream ( void *  ptr,
Nz::UInt64  size 
)

Sets this with a raw memory and a size.

Parameters
ptrPointer to raw memory
sizeSize that can be read
Remarks
If preallocated space of ptr is less than the size, the behaviour is undefined

◆ SetStream() [4/4]

void Nz::ByteStream::SetStream ( const void *  ptr,
Nz::UInt64  size 
)

Sets this with a raw memory and a size.

Parameters
ptrConstant pointer to raw memory
sizeSize that can be read
Remarks
If preallocated space of ptr is less than the size, the behaviour is undefined

◆ Write()

void Nz::ByteStream::Write ( const void *  data,
std::size_t  size 
)
inline

Writes data.

Returns
Number of data written
Parameters
bufferPreallocated buffer containing information to write
sizeSize of the writting and thus of the buffer
Remarks
Produces a NazaraAssert if buffer is nullptr

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