panda3d.core.Datagram

class Datagram

Bases: TypedObject

An ordered list of data elements, formatted in memory for transmission over a socket or writing to a data file.

Data elements should be added one at a time, in order, to the Datagram. The nature and contents of the data elements are totally up to the user. When a Datagram has been transmitted and received, its data elements may be extracted using a DatagramIterator; it is up to the caller to know the correct type of each data element in order.

A Datagram is itself headerless; it is simply a collection of data elements.

Inheritance diagram

Inheritance diagram of Datagram

__init__() → None
__init__(from: Datagram) → None
__init__(copy: Datagram) → None
__init__(data: bytes) → None

Constructs a datagram from an existing block of data.

addBeFloat32(value: PN_float32) → None

Adds a 32-bit single-precision big-endian floating-point number to the datagram.

addBeFloat64(value: PN_float64) → None

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

addBeInt16(value: int16_t) → None

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

addBeInt32(value: int32_t) → None

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

addBeInt64(value: int64_t) → None

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

addBeUint16(value: uint16_t) → None

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

addBeUint32(value: uint32_t) → None

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

addBeUint64(value: uint64_t) → None

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

addBlob(param0: bytes) → None

Adds a variable-length binary blob to the datagram. This actually adds a count followed by n bytes.

addBlob32(param0: bytes) → None

Adds a variable-length binary blob to the datagram, using a 32-bit length field to allow very long blobs.

addBool(value: bool) → None

Adds a boolean value to the datagram.

addFixedString(str: str, size: size_t) → None

Adds a fixed-length string to the datagram. 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(value: PN_float32) → None

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

addFloat64(value: PN_float64) → None

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

addInt16(value: int16_t) → None

Adds a signed 16-bit integer to the datagram.

addInt32(value: int32_t) → None

Adds a signed 32-bit integer to the datagram.

addInt64(value: int64_t) → None

Adds a signed 64-bit integer to the datagram.

addInt8(value: int8_t) → None

Adds a signed 8-bit integer to the datagram.

addStdfloat(value: float) → None

Adds either a 32-bit or a 64-bit floating-point number, according to setStdfloatDouble().

addString(str: str) → None

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

addString32(str: str) → None

Adds a variable-length string to the datagram, using a 32-bit length field to allow very long strings.

addUint16(value: uint16_t) → None

Adds an unsigned 16-bit integer to the datagram.

addUint32(value: uint32_t) → None

Adds an unsigned 32-bit integer to the datagram.

addUint64(value: uint64_t) → None

Adds an unsigned 64-bit integer to the datagram.

addUint8(value: uint8_t) → None

Adds an unsigned 8-bit integer to the datagram.

addWstring(str: str) → None

Adds a variable-length wstring to the datagram.

addZString(str: str) → None

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

appendData(data: bytes) → None

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

assign(from: Datagram) → Datagram
Return type

Datagram

assign(copy: Datagram) → Datagram
Return type

Datagram

clear() → None

Resets the datagram to empty, in preparation for building up a new datagram.

copyArray(data: CPTA_uchar) → None

Replaces the data in the Datagram with a copy of the data in the indicated CPTA_uchar. Unlike setArray(), a complete copy is made of the data; subsequent changes to the Datagram will not change the source CPTA_uchar.

dumpHex(out: ostream, indent: int) → None

Writes a representation of the entire datagram contents, as a sequence of hex (and ASCII) values.

getArray() → CPTA_uchar

Returns a const pointer to the actual data in the Datagram.

Return type

CPTA_uchar

static getClassType() → TypeHandle
Return type

TypeHandle

getLength() → size_t

Returns the number of bytes in the datagram.

Return type

size_t

getMessage() → object

Returns the datagram’s data as a string.

getStdfloatDouble() → bool

Returns the stdfloat_double flag. See setStdfloatDouble().

modifyArray() → PTA_uchar

Returns a modifiable pointer to the actual data in the Datagram.

Return type

PTA_uchar

output(out: ostream) → None

Write a string representation of this instance to <out>.

padBytes(size: size_t) → None

Adds the indicated number of zero bytes to the datagram.

setArray(data: PTA_uchar) → None

Replaces the data in the Datagram with the data in the indicated PTA_uchar. This is assignment by reference: subsequent changes to the Datagram will also change the source PTA_uchar.

setStdfloatDouble(stdfloat_double: bool) → None

Changes the stdfloat_double flag, which defines the operation performed by addStdfloat() and DatagramIterator.getStdfloat(). When this is true, addStdfloat() adds a 64-bit floating-point number; when it is false, it adds a 32-bit floating-point number. The default is based on the STDFLOAT_DOUBLE compilation flag.

write(out: ostream, indent: int) → None

Write a string representation of this instance to <out>.