# Poco

# class BinaryReader

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

## Description

This class reads basic types 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.

## Member Summary

Member Functions: bad, byteOrder, eof, fail, good, operator >>, read7BitEncoded, readBOM, readRaw, 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.

## Destructor

### ~BinaryReader

~BinaryReader();

Destroys the BinaryReader.

## Member Functions

### bad

bool bad();

Returns _istr.bad();

### byteOrder

StreamByteOrder byteOrder() const;

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

### eof

bool eof();

Returns _istr.eof();

### fail

bool fail();

Returns _istr.fail();

### good

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 >> (
Int64 & value
);

### operator >>

BinaryReader & operator >> (
UInt64 & value
);

### operator >>

BinaryReader & operator >> (
std::string & 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.

### 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.

### stream

std::istream & stream() const;

Returns the underlying stream.