StreamWriter

class StreamWriter

A StreamWriter object is used to write sequential binary data directly to an ostream. Its interface is very similar to Datagram by design; it’s primarily intended as a convenience to eliminate the overhead of writing bytes to a Datagram and then writing the Datagram to a stream.

Inheritance diagram

Inheritance diagram of StreamWriter

explicit StreamWriter(std::ostream *out, bool owns_stream)
StreamWriter(StreamWriter const &copy)

The copy constructor does not copy ownership of the stream.

The move constructor steals ownership of the stream.

void add_be_float32(float value)

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

void add_be_float64(PN_float64 value)

Adds a 64-bit big-endian floating-point number to the streamWriter.

void add_be_int16(int16_t value)

These functions pack numbers big-endian, in case that’s desired.

Adds a signed 16-bit big-endian integer to the streamWriter.

void add_be_int32(int32_t value)

Adds a signed 32-bit big-endian integer to the streamWriter.

void add_be_int64(int64_t value)

Adds a signed 64-bit big-endian integer to the streamWriter.

void add_be_uint16(uint16_t value)

Adds an unsigned 16-bit big-endian integer to the streamWriter.

void add_be_uint32(uint32_t value)

Adds an unsigned 32-bit big-endian integer to the streamWriter.

void add_be_uint64(uint64_t value)

Adds an unsigned 64-bit big-endian integer to the streamWriter.

void add_bool(bool value)

Adds a boolean value to the stream.

void add_fixed_string(std::string const &str, std::size_t size)

Adds a fixed-length string to the stream. If the string given is less than the requested size, this will pad the string out with zeroes; if it is greater than the requested size, this will silently truncate the string.

void add_float32(float value)

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

void add_float64(PN_float64 value)

Adds a 64-bit floating-point number to the stream.

void add_int16(int16_t value)

The default numeric packing is little-endian.

Adds a signed 16-bit integer to the stream.

void add_int32(int32_t value)

Adds a signed 32-bit integer to the stream.

void add_int64(int64_t value)

Adds a signed 64-bit integer to the stream.

void add_int8(int8_t value)

Adds a signed 8-bit integer to the stream.

void add_string(std::string const &str)

Adds a variable-length string to the stream. This actually adds a count followed by n bytes.

void add_string32(std::string const &str)

Adds a variable-length string to the stream, using a 32-bit length field.

void add_uint16(uint16_t value)

Adds an unsigned 16-bit integer to the stream.

void add_uint32(uint32_t value)

Adds an unsigned 32-bit integer to the stream.

void add_uint64(uint64_t value)

Adds an unsigned 64-bit integer to the stream.

void add_uint8(uint8_t value)

Adds an unsigned 8-bit integer to the stream.

void add_z_string(std::string str)

Adds a variable-length string to the stream, as a NULL-terminated string.

void append_data(PyObject *data)

Appends some more raw data to the end of the streamWriter.

void flush(void)

Calls flush() on the underlying stream.

std::ostream *get_ostream(void) const

Returns the stream in use.

void pad_bytes(std::size_t size)

Adds the indicated number of zero bytes to the stream.

void write(std::string const &str)

A synonym of append_data(). This is useful when assigning the StreamWriter to sys.stderr and/or sys.stdout in Python.