Poco

class BinaryReader

File Information

Library: Foundation
Package: Streams
Header: Poco/BinaryReader.h

Description

This class reads basic types (and std::vectors thereof) in binary form into an input stream. It provides an extractor-based interface similar to istream. The reader also supports automatic conversion from big-endian (network byte order) to little-endian and vice-versa. Use a BinaryWriter to create a stream suitable for a BinaryReader.

Inheritance

Known Derived Classes: BasicMemoryBinaryReader

Member Summary

Member Functions: available, bad, byteOrder, eof, fail, good, operator >>, read7BitEncoded, readBOM, readCString, readRaw, setExceptions, stream

Enumerations

StreamByteOrder

NATIVE_BYTE_ORDER = 1

the host's native byte-order

BIG_ENDIAN_BYTE_ORDER = 2

big-endian (network) byte-order

NETWORK_BYTE_ORDER = 2

big-endian (network) byte-order

LITTLE_ENDIAN_BYTE_ORDER = 3

little-endian byte-order

UNSPECIFIED_BYTE_ORDER = 4

unknown, byte-order will be determined by reading the byte-order mark

Constructors

BinaryReader

BinaryReader(
    std::istream & istr,
    StreamByteOrder byteOrder = NATIVE_BYTE_ORDER
);

Creates the BinaryReader.

BinaryReader

BinaryReader(
    std::istream & istr,
    TextEncoding & encoding,
    StreamByteOrder byteOrder = NATIVE_BYTE_ORDER
);

Creates the BinaryReader using the given TextEncoding.

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

Destructor

~BinaryReader

~BinaryReader();

Destroys the BinaryReader.

Member Functions

available inline

std::streamsize available() const;

Returns the number of available bytes in the stream.

bad inline

bool bad();

Returns _istr.bad();

byteOrder inline

StreamByteOrder byteOrder() const;

Returns the byte-order used by the reader, which is either BIG_ENDIAN_BYTE_ORDER or LITTLE_ENDIAN_BYTE_ORDER.

eof inline

bool eof();

Returns _istr.eof();

fail inline

bool fail();

Returns _istr.fail();

good inline

bool good();

Returns _istr.good();

operator >>

BinaryReader & operator >> (
    bool & value
);

operator >>

BinaryReader & operator >> (
    char & value
);

operator >>

BinaryReader & operator >> (
    unsigned char & value
);

operator >>

BinaryReader & operator >> (
    signed char & value
);

operator >>

BinaryReader & operator >> (
    short & value
);

operator >>

BinaryReader & operator >> (
    unsigned short & value
);

operator >>

BinaryReader & operator >> (
    int & value
);

operator >>

BinaryReader & operator >> (
    unsigned int & value
);

operator >>

BinaryReader & operator >> (
    long & value
);

operator >>

BinaryReader & operator >> (
    unsigned long & value
);

operator >>

BinaryReader & operator >> (
    float & value
);

operator >>

BinaryReader & operator >> (
    double & value
);

operator >>

BinaryReader & operator >> (
    long long & value
);

operator >>

BinaryReader & operator >> (
    unsigned long long & value
);

operator >>

BinaryReader & operator >> (
    std::string & value
);

operator >> inline

template < typename T > BinaryReader & operator >> (
    std::vector < T > & value
);

read7BitEncoded

void read7BitEncoded(
    UInt32 & value
);

Reads a 32-bit unsigned integer in compressed format. See BinaryWriter::write7BitEncoded() for a description of the compression algorithm.

read7BitEncoded

void read7BitEncoded(
    UInt64 & value
);

Reads a 64-bit unsigned integer in compressed format. See BinaryWriter::write7BitEncoded() for a description of the compression algorithm.

readBOM

void readBOM();

Reads a byte-order mark from the stream and configures the reader for the encountered byte order. A byte-order mark is a 16-bit integer with a value of 0xFEFF, written in host byte order.

readCString

void readCString(
    std::string & value
);

Reads zero-terminated C-string into value.

readRaw

void readRaw(
    std::streamsize length,
    std::string & value
);

Reads length bytes of raw data into value.

readRaw

void readRaw(
    char * buffer,
    std::streamsize length
);

Reads length bytes of raw data into buffer.

setExceptions inline

void setExceptions(
    std::ios_base::iostate st = (std::istream::failbit | std::istream::badbit)
);

Sets the stream to throw exception on specified state (default failbit and badbit);

stream inline

std::istream & stream() const;

Returns the underlying stream.