Datagram
from panda3d.core import Datagram
- class Datagram
Bases:
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
- __init__()
- __init__(copy: Datagram)
- __init__(data: bytes)
Constructs a datagram from an existing block of data.
- addBeFloat32(value: float)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
- addBlob(param0: bytes)
Adds a variable-length binary blob to the datagram. This actually adds a count followed by n bytes.
- addBlob32(param0: bytes)
Adds a variable-length binary blob to the datagram, using a 32-bit length field to allow very long blobs.
- addFixedString(str: str, size: int)
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: float)
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.
- addInt8(value: int8_t)
Adds a signed 8-bit integer to the datagram.
- addStdfloat(value: float)
Adds either a 32-bit or a 64-bit floating-point number, according to
setStdfloatDouble()
.
- addString(str: str)
Adds a variable-length string to the datagram. This actually adds a count followed by n bytes.
- addString32(str: str)
Adds a variable-length string to the datagram, using a 32-bit length field to allow very long strings.
- addUint8(value: uint8_t)
Adds an unsigned 8-bit integer to the datagram.
- clear()
Resets the datagram to empty, in preparation for building up a new datagram.
- copyArray(data: CPTA_uchar)
Replaces the data in the Datagram with a copy of the data in the indicated
CPTA_uchar
. UnlikesetArray()
, a complete copy is made of the data; subsequent changes to the Datagram will not change the sourceCPTA_uchar
.
- dumpHex(out: ostream, indent: int)
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.
- static getClassType() TypeHandle
- getStdfloatDouble() bool
Returns the stdfloat_double flag. See
setStdfloatDouble()
.
- setArray(data: PTA_uchar)
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 sourcePTA_uchar
.
- setStdfloatDouble(stdfloat_double: bool)
Changes the stdfloat_double flag, which defines the operation performed by
addStdfloat()
andDatagramIterator.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.