Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::BinaryWriter Class Reference

#include <BinaryWriter.h>

+ Inheritance diagram for Poco::BinaryWriter:

Public Types

enum  StreamByteOrder { NATIVE_BYTE_ORDER = 1 , BIG_ENDIAN_BYTE_ORDER = 2 , NETWORK_BYTE_ORDER = 2 , LITTLE_ENDIAN_BYTE_ORDER = 3 }
 

Public Member Functions

 BinaryWriter (std::ostream &ostr, StreamByteOrder byteOrder=NATIVE_BYTE_ORDER)
 
 BinaryWriter (std::ostream &ostr, TextEncoding &encoding, StreamByteOrder byteOrder=NATIVE_BYTE_ORDER)
 Creates the BinaryWriter.
 
 ~BinaryWriter ()
 
BinaryWriteroperator<< (bool value)
 Destroys the BinaryWriter.
 
BinaryWriteroperator<< (char value)
 
BinaryWriteroperator<< (unsigned char value)
 
BinaryWriteroperator<< (signed char value)
 
BinaryWriteroperator<< (short value)
 
BinaryWriteroperator<< (unsigned short value)
 
BinaryWriteroperator<< (int value)
 
BinaryWriteroperator<< (unsigned int value)
 
BinaryWriteroperator<< (long value)
 
BinaryWriteroperator<< (unsigned long value)
 
BinaryWriteroperator<< (float value)
 
BinaryWriteroperator<< (double value)
 
BinaryWriteroperator<< (const std::string &value)
 
BinaryWriteroperator<< (const char *value)
 
template<typename T >
BinaryWriteroperator<< (const std::vector< T > &value)
 
void write7BitEncoded (UInt32 value)
 
void writeRaw (const std::string &rawData)
 
void writeRaw (const char *buffer, std::streamsize length)
 Writes the string as-is to the stream.
 
void writeBOM ()
 Writes length raw bytes from the given buffer to the stream.
 
void flush ()
 
bool good ()
 Flushes the underlying stream.
 
bool fail ()
 Returns _ostr.good();.
 
bool bad ()
 Returns _ostr.fail();.
 
std::ostream & stream () const
 Returns _ostr.bad();.
 
StreamByteOrder byteOrder () const
 Returns the underlying stream.
 

Private Attributes

std::ostream & _ostr
 
bool _flipBytes
 
TextConverter * _pTextConverter
 

Detailed Description

This class writes basic types (and std::vectors of these) in binary form into an output stream. It provides an inserter-based interface similar to ostream. The writer also supports automatic conversion from big-endian (network byte order) to little-endian and vice-versa. Use a BinaryReader to read from a stream created by a BinaryWriter. Be careful when exchanging data between systems with different data type sizes (e.g., 32-bit and 64-bit architectures), as the sizes of some of the basic types may be different. For example, writing a long integer on a 64-bit system and reading it on a 32-bit system may yield an incorrent result. Use fixed-size types (Int32, Int64, etc.) in such a case.

Definition at line 35 of file BinaryWriter.h.

Member Enumeration Documentation

◆ StreamByteOrder

Enumerator
NATIVE_BYTE_ORDER 
BIG_ENDIAN_BYTE_ORDER 

the host's native byte-order

NETWORK_BYTE_ORDER 

big-endian (network) byte-order

LITTLE_ENDIAN_BYTE_ORDER 

big-endian (network) byte-order

Definition at line 50 of file BinaryWriter.h.

Constructor & Destructor Documentation

◆ BinaryWriter() [1/2]

Poco::BinaryWriter::BinaryWriter ( std::ostream & ostr,
StreamByteOrder byteOrder = NATIVE_BYTE_ORDER )

◆ BinaryWriter() [2/2]

Poco::BinaryWriter::BinaryWriter ( std::ostream & ostr,
TextEncoding & encoding,
StreamByteOrder byteOrder = NATIVE_BYTE_ORDER )

Creates the BinaryWriter.

◆ ~BinaryWriter()

Poco::BinaryWriter::~BinaryWriter ( )

Creates the BinaryWriter using the given TextEncoding.

Strings will be converted from the currently set global encoding (see Poco::TextEncoding::global()) to the specified encoding.

Member Function Documentation

◆ bad()

bool Poco::BinaryWriter::bad ( )
inline

Returns _ostr.fail();.

Definition at line 250 of file BinaryWriter.h.

◆ byteOrder()

BinaryWriter::StreamByteOrder Poco::BinaryWriter::byteOrder ( ) const
inline

Returns the underlying stream.

Definition at line 256 of file BinaryWriter.h.

◆ fail()

bool Poco::BinaryWriter::fail ( )
inline

Returns _ostr.good();.

Definition at line 244 of file BinaryWriter.h.

◆ flush()

void Poco::BinaryWriter::flush ( )

Writes a byte-order mark to the stream. A byte order mark is a 16-bit integer with a value of 0xFEFF, written in host byte-order. A BinaryReader uses the byte-order mark to determine the byte-order of the stream.

◆ good()

bool Poco::BinaryWriter::good ( )
inline

Flushes the underlying stream.

Definition at line 238 of file BinaryWriter.h.

◆ operator<<() [1/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( bool value)

Destroys the BinaryWriter.

◆ operator<<() [2/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( char value)

◆ operator<<() [3/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( const char * value)

◆ operator<<() [4/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( const std::string & value)

◆ operator<<() [5/15]

template<typename T >
BinaryWriter & Poco::BinaryWriter::operator<< ( const std::vector< T > & value)
inline

Definition at line 92 of file BinaryWriter.h.

◆ operator<<() [6/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( double value)

◆ operator<<() [7/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( float value)

◆ operator<<() [8/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( int value)

◆ operator<<() [9/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( long value)

◆ operator<<() [10/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( short value)

◆ operator<<() [11/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( signed char value)

◆ operator<<() [12/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( unsigned char value)

◆ operator<<() [13/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( unsigned int value)

◆ operator<<() [14/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( unsigned long value)

◆ operator<<() [15/15]

BinaryWriter & Poco::BinaryWriter::operator<< ( unsigned short value)

◆ stream()

std::ostream & Poco::BinaryWriter::stream ( ) const
inline

Returns _ostr.bad();.

Definition at line 232 of file BinaryWriter.h.

◆ write7BitEncoded()

void Poco::BinaryWriter::write7BitEncoded ( UInt32 value)

◆ writeBOM()

void Poco::BinaryWriter::writeBOM ( )

Writes length raw bytes from the given buffer to the stream.

◆ writeRaw() [1/2]

void Poco::BinaryWriter::writeRaw ( const char * buffer,
std::streamsize length )

Writes the string as-is to the stream.

◆ writeRaw() [2/2]

void Poco::BinaryWriter::writeRaw ( const std::string & rawData)

Writes a 32-bit unsigned integer in a compressed format. The value is written out seven bits at a time, starting with the seven least-significant bits. The high bit of a byte indicates whether there are more bytes to be written after this one. If value will fit in seven bits, it takes only one byte of space. If value will not fit in seven bits, the high bit is set on the first byte and written out. value is then shifted by seven bits and the next byte is written. This process is repeated until the entire integer has been written.

Member Data Documentation

◆ _flipBytes

bool Poco::BinaryWriter::_flipBytes
private

Definition at line 162 of file BinaryWriter.h.

◆ _ostr

std::ostream& Poco::BinaryWriter::_ostr
private

Returns the byte ordering used by the writer, which is either BIG_ENDIAN_BYTE_ORDER or LITTLE_ENDIAN_BYTE_ORDER.

Definition at line 161 of file BinaryWriter.h.

◆ _pTextConverter

TextConverter* Poco::BinaryWriter::_pTextConverter
private

Definition at line 163 of file BinaryWriter.h.


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