Datagram¶
from acron.core import Datagram
- class Datagram¶
Bases:
Bases:
TypedObjectAn 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
digraph inheritance63b9fbcfc0 { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "Datagram" [URL="acron.core.Datagram.html#acron.core.Datagram",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedObject" -> "Datagram" [arrowsize=0.75,style=""]; "TypedObject" [URL="acron.core.TypedObject.html#acron.core.TypedObject",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "TypedObject" [arrowsize=0.75,style=""]; }- __bytes__()¶
- __eq__()¶
- __init__()¶
Constructs a datagram from an existing block of data.
Constructs a datagram from an existing block of data.
- __lt__()¶
- __ne__()¶
- __reduce__()¶
- add_be_float32()¶
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
- add_be_float64()¶
Adds a 64-bit big-endian floating-point number to the datagram.
- add_be_int16()¶
These functions pack numbers big-endian, in case that’s desired.
Adds a signed 16-bit big-endian integer to the datagram.
- add_be_int32()¶
Adds a signed 32-bit big-endian integer to the datagram.
- add_be_int64()¶
Adds a signed 64-bit big-endian integer to the datagram.
- add_be_uint16()¶
Adds an unsigned 16-bit big-endian integer to the datagram.
- add_be_uint32()¶
Adds an unsigned 32-bit big-endian integer to the datagram.
- add_be_uint64()¶
Adds an unsigned 64-bit big-endian integer to the datagram.
- add_blob()¶
Adds a variable-length binary blob to the datagram. This actually adds a count followed by n bytes.
- add_blob32()¶
Adds a variable-length binary blob to the datagram, using a 32-bit length field to allow very long blobs.
- add_bool()¶
Adds a boolean value to the datagram.
- add_fixed_string()¶
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.
- add_float32()¶
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.
- add_float64()¶
Adds a 64-bit floating-point number to the datagram.
- add_int16()¶
The default numeric packing is little-endian.
Adds a signed 16-bit integer to the datagram.
- add_int32()¶
Adds a signed 32-bit integer to the datagram.
- add_int64()¶
Adds a signed 64-bit integer to the datagram.
- add_int8()¶
Adds a signed 8-bit integer to the datagram.
- add_stdfloat()¶
Adds either a 32-bit or a 64-bit floating-point number, according to
set_stdfloat_double().
- add_string()¶
Adds a variable-length string to the datagram. This actually adds a count followed by n bytes.
- add_string32()¶
Adds a variable-length string to the datagram, using a 32-bit length field to allow very long strings.
- add_uint16()¶
Adds an unsigned 16-bit integer to the datagram.
- add_uint32()¶
Adds an unsigned 32-bit integer to the datagram.
- add_uint64()¶
Adds an unsigned 64-bit integer to the datagram.
- add_uint8()¶
Adds an unsigned 8-bit integer to the datagram.
- add_wstring()¶
Adds a variable-length wstring to the datagram.
- add_z_string()¶
Adds a variable-length string to the datagram, as a NULL-terminated string.
- append_data()¶
Appends some more raw data to the end of the datagram.
Appends some more raw data to the end of the datagram.
- assign()¶
- clear()¶
Resets the datagram to empty, in preparation for building up a new datagram.
- copy_array()¶
Replaces the data in the Datagram with a copy of the data in the indicated
CPTA_uchar. Unlikeset_array(), a complete copy is made of the data; subsequent changes to the Datagram will not change the sourceCPTA_uchar.
- dump_hex()¶
Writes a representation of the entire datagram contents, as a sequence of hex (and ASCII) values.
- get_array()¶
Returns a const pointer to the actual data in the Datagram.
- static get_class_type()¶
- get_length()¶
Returns the number of bytes in the datagram.
- get_message()¶
Returns the datagram’s data as a string.
- get_stdfloat_double()¶
Returns the stdfloat_double flag. See
set_stdfloat_double().
- modify_array()¶
Returns a modifiable pointer to the actual data in the Datagram.
- output()¶
Write a string representation of this instance to <out>.
- pad_bytes()¶
Adds the indicated number of zero bytes to the datagram.
- set_array()¶
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.
- set_stdfloat_double()¶
Changes the stdfloat_double flag, which defines the operation performed by
add_stdfloat()andDatagramIterator.get_stdfloat(). When this is true,add_stdfloat()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()¶
Write a string representation of this instance to <out>.