Panda3D
Public Member Functions | Public Attributes | List of all members
StreamWriter Class Reference

A StreamWriter object is used to write sequential binary data directly to an ostream. More...

Public Member Functions

 __init__ (const StreamWriter copy)
 The copy constructor does not copy ownership of the stream. More...
 
 __init__ (Ostream out, bool owns_stream)
 
 addBeFloat32 (float value)
 Adds a 32-bit single-precision big-endian floating-point number to the stream. More...
 
 addBeFloat64 (PNFloat64 value)
 Adds a 64-bit big-endian floating-point number to the streamWriter. More...
 
 addBeInt16 (int16_t value)
 Adds a signed 16-bit big-endian integer to the streamWriter. More...
 
 addBeInt32 (int32_t value)
 Adds a signed 32-bit big-endian integer to the streamWriter. More...
 
 addBeInt64 (int64_t value)
 Adds a signed 64-bit big-endian integer to the streamWriter. More...
 
 addBeUint16 (uint16_t value)
 Adds an unsigned 16-bit big-endian integer to the streamWriter. More...
 
 addBeUint32 (uint32_t value)
 Adds an unsigned 32-bit big-endian integer to the streamWriter. More...
 
 addBeUint64 (uint64_t value)
 Adds an unsigned 64-bit big-endian integer to the streamWriter. More...
 
 addBool (bool value)
 Adds a boolean value to the stream. More...
 
 addFixedString (str str, int size)
 Adds a fixed-length string to the stream. More...
 
 addFloat32 (float value)
 Adds a 32-bit single-precision floating-point number to the stream. More...
 
 addFloat64 (PNFloat64 value)
 Adds a 64-bit floating-point number to the stream. More...
 
 addInt16 (int16_t value)
 Adds a signed 16-bit integer to the stream. More...
 
 addInt32 (int32_t value)
 Adds a signed 32-bit integer to the stream. More...
 
 addInt64 (int64_t value)
 Adds a signed 64-bit integer to the stream. More...
 
 addInt8 (int8_t value)
 Adds a signed 8-bit integer to the stream. More...
 
 addString (str str)
 Adds a variable-length string to the stream. More...
 
 addString32 (str str)
 Adds a variable-length string to the stream, using a 32-bit length field. More...
 
 addUint16 (uint16_t value)
 Adds an unsigned 16-bit integer to the stream. More...
 
 addUint32 (uint32_t value)
 Adds an unsigned 32-bit integer to the stream. More...
 
 addUint64 (uint64_t value)
 Adds an unsigned 64-bit integer to the stream. More...
 
 addUint8 (uint8_t value)
 Adds an unsigned 8-bit integer to the stream. More...
 
 addZString (str str)
 Adds a variable-length string to the stream, as a NULL-terminated string. More...
 
 appendData (object data)
 
 flush ()
 Calls flush() on the underlying stream. More...
 
Ostream getOstream ()
 Returns the stream in use. More...
 
StreamWriter operator= (const StreamWriter copy)
 
 padBytes (int size)
 Adds the indicated number of zero bytes to the stream. More...
 
 write (str str)
 A synonym of append_data(). More...
 

Public Attributes

Ostream ostream
 Returns the ostream this object is wrapping. More...
 
int softspace
 Python 2 needs this for printing to work correctly. More...
 

Detailed Description

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.

Member Function Documentation

◆ __init__() [1/2]

__init__ ( const StreamWriter  copy)

The copy constructor does not copy ownership of the stream.

◆ __init__() [2/2]

__init__ ( Ostream  out,
bool  owns_stream 
)

◆ addBeFloat32()

addBeFloat32 ( 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.

◆ addBeFloat64()

addBeFloat64 ( PNFloat64  value)

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

◆ addBeInt16()

addBeInt16 ( int16_t  value)

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

◆ addBeInt32()

addBeInt32 ( int32_t  value)

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

◆ addBeInt64()

addBeInt64 ( int64_t  value)

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

◆ addBeUint16()

addBeUint16 ( uint16_t  value)

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

◆ addBeUint32()

addBeUint32 ( uint32_t  value)

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

◆ addBeUint64()

addBeUint64 ( uint64_t  value)

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

◆ addBool()

addBool ( bool  value)

Adds a boolean value to the stream.

◆ addFixedString()

addFixedString ( str  str,
int  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.

◆ addFloat32()

addFloat32 ( 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.

◆ addFloat64()

addFloat64 ( PNFloat64  value)

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

◆ addInt16()

addInt16 ( int16_t  value)

Adds a signed 16-bit integer to the stream.

◆ addInt32()

addInt32 ( int32_t  value)

Adds a signed 32-bit integer to the stream.

◆ addInt64()

addInt64 ( int64_t  value)

Adds a signed 64-bit integer to the stream.

◆ addInt8()

addInt8 ( int8_t  value)

Adds a signed 8-bit integer to the stream.

◆ addString()

addString ( str  str)

Adds a variable-length string to the stream.

This actually adds a count followed by n bytes.

◆ addString32()

addString32 ( str  str)

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

◆ addUint16()

addUint16 ( uint16_t  value)

Adds an unsigned 16-bit integer to the stream.

◆ addUint32()

addUint32 ( uint32_t  value)

Adds an unsigned 32-bit integer to the stream.

◆ addUint64()

addUint64 ( uint64_t  value)

Adds an unsigned 64-bit integer to the stream.

◆ addUint8()

addUint8 ( uint8_t  value)

Adds an unsigned 8-bit integer to the stream.

◆ addZString()

addZString ( str  str)

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

◆ appendData()

appendData ( object  data)

◆ flush()

flush ( )

Calls flush() on the underlying stream.

◆ getOstream()

Ostream getOstream ( )

Returns the stream in use.

◆ operator=()

StreamWriter operator= ( const StreamWriter  copy)

◆ padBytes()

padBytes ( int  size)

Adds the indicated number of zero bytes to the stream.

◆ write()

write ( str  str)

A synonym of append_data().

This is useful when assigning the StreamWriter to sys.stderr and/or sys.stdout in Python.

Member Data Documentation

◆ ostream

Ostream ostream

Returns the ostream this object is wrapping.

◆ softspace

int softspace

Python 2 needs this for printing to work correctly.