StreamReader

class StreamReader

A class to read sequential binary data directly from an istream. Its interface is similar to DatagramIterator by design; see also StreamWriter.

Inheritance diagram

Inheritance diagram of StreamReader

explicit StreamReader(std::istream *in, bool owns_stream)
StreamReader(StreamReader const &copy)

If owns_stream is true, the stream pointer will be deleted when the StreamReader destructs.

The copy constructor does not copy ownership of the stream.

std::size_t extract_bytes(unsigned char *into, std::size_t size)
PyObject *extract_bytes(std::size_t size)

Extracts the indicated number of bytes in the stream into the given character buffer. Assumes that the buffer is big enough to hold the requested number of bytes. Returns the number of bytes that were successfully written.

Extracts the indicated number of bytes in the stream and returns them as a string. Returns empty string at end-of-file.

float get_be_float32(void)

Extracts a 32-bit single-precision big-endian floating-point number. Since this kind of float is not necessarily portable across different architectures, special care is required.

PN_float64 get_be_float64(void)

Extracts a 64-bit big-endian floating-point number.

int16_t get_be_int16(void)

Extracts a signed big-endian 16-bit integer.

int32_t get_be_int32(void)

Extracts a signed big-endian 32-bit integer.

int64_t get_be_int64(void)

Extracts a signed big-endian 64-bit integer.

uint16_t get_be_uint16(void)

Extracts an unsigned big-endian 16-bit integer.

uint32_t get_be_uint32(void)

Extracts an unsigned big-endian 32-bit integer.

uint64_t get_be_uint64(void)

Extracts an unsigned big-endian 64-bit integer.

bool get_bool(void)

Extracts a boolean value.

std::string get_fixed_string(std::size_t size)

Extracts a fixed-length string. However, if a zero byte occurs within the string, it marks the end of the string.

float get_float32(void)

Extracts a 32-bit single-precision floating-point number. Since this kind of float is not necessarily portable across different architectures, special care is required.

PN_float64 get_float64(void)

Extracts a 64-bit floating-point number.

int16_t get_int16(void)

Extracts a signed 16-bit integer.

int32_t get_int32(void)

Extracts a signed 32-bit integer.

int64_t get_int64(void)

Extracts a signed 64-bit integer.

int8_t get_int8(void)

Extracts a signed 8-bit integer.

std::istream *get_istream(void) const

Returns the stream in use.

std::string get_string(void)

Extracts a variable-length string.

std::string get_string32(void)

Extracts a variable-length string with a 32-bit length field.

uint16_t get_uint16(void)

Extracts an unsigned 16-bit integer.

uint32_t get_uint32(void)

Extracts an unsigned 32-bit integer.

uint64_t get_uint64(void)

Extracts an unsigned 64-bit integer.

uint8_t get_uint8(void)

Extracts an unsigned 8-bit integer.

std::string get_z_string(void)

Extracts a variable-length string, as a NULL-terminated string.

PyObject *readline(void)

Assumes the stream represents a text file, and extracts one line up to and including the trailing newline character. Returns empty string when the end of file is reached.

The interface here is intentionally designed to be similar to that for Python’s File.readline() function.

PyObject *readlines(void)
void skip_bytes(std::size_t size)

Skips over the indicated number of bytes in the stream.