pyrtma.core_defs.MessageBase

class MessageBase[source]

Bases: Structure

MessageBase base class

This class should be treated as if abstract and not instantiated directly.

Methods

copy

Generate a copy of a message structure

from_dict

Generate message instance from dictionary

from_json

Generate message instance from JSON string

from_random

Generate message instance with random values

get_field_raw

return copy of raw bytes for ctypes field

hexdump

hexdump of message

pretty_print

Generate formatted message structure string for pretty printing

to_dict

Convert message to dictionary

to_json

Convert message to json string

Attributes

size

classmethod copy(m)[source]

Generate a copy of a message structure

Parameters:

m (TypeVar(MB, bound= MessageBase)) – Message structure to copy

Return type:

TypeVar(MB, bound= MessageBase)

classmethod from_dict(data)[source]

Generate message instance from dictionary

Parameters:

data (Dict[str, Any]) – Message dictionary

Raises:

JSONDecodingError – Unable to decode dictionary

Return type:

TypeVar(MB, bound= MessageBase)

classmethod from_json(s)[source]

Generate message instance from JSON string

Parameters:

s (str) – Message JSON string

Return type:

TypeVar(MB, bound= MessageBase)

classmethod from_random()[source]

Generate message instance with random values

Return type:

TypeVar(MB, bound= MessageBase)

get_field_raw(name)[source]

return copy of raw bytes for ctypes field

Parameters:

name (str) – Message fieldname

Raises:

KeyError – Invalid fieldname

Returns:

Copy of message field data bytes

Return type:

bytes

hexdump(length=16, sep=' ')[source]

hexdump of message

Parameters:
  • length (int, optional) – Row length. Defaults to 16.

  • sep (str, optional) – Separator for non-printable ascii chars. Defaults to ” “.

pretty_print(add_tabs=0)[source]

Generate formatted message structure string for pretty printing

Parameters:

add_tabs (int, optional) – Indentation level, used for recursively calling. Defaults to 0.

Returns:

Formatted string

Return type:

str

to_dict()[source]

Convert message to dictionary

Returns:

Message dictionary

Return type:

Dict[str, Any]

to_json(minify=False, **kwargs)[source]

Convert message to json string

Parameters:
  • minify (bool, optional) – Flag to minify (compact format). Defaults to False.

  • json.dumps (kwargs for) –

Returns:

json string

Return type:

str