otupy.transfers.mqtt.message.Message

class Message(headers: Headers = None, body: Body = None)

Bases: Record

MQTT Message representation

This class implements the HTTP-specific representation of the OpenC2 Message metadata. The OpenC2 Message metadata are described in Table 3.1 of the Language Specification as message elements, but they are not framed in a concrete structure. The HTTP Specification defines such structure in Sec. 3.3.2, and this class is its implementation. The MQTT specification mandates the usage of the Message type defined in Table 3-1 of the Specification, but does not provide serialization requirements.

The methods of this class are meant to translate back and for the otupy Message class.

Methods

fromdict

Builds instance from dictionary

get

Create an otupy Message from MQTT Message

set

Create MQTT Message from otupy Message

todict

Converts to dictionary

Attributes

body

Contains the Content

headers

Contains the Message metadata

__init__(headers: Headers = None, body: Body = None) None
body: Body = None

Contains the Content

classmethod fromdict(dic, e)

Builds instance from dictionary

It is used during deserialization to create an otupy instance from the text message. It takes an Encoder instance that is used to recursively build instances of the inner objects (the Encoder provides standard methods to create instances of base objects like strings, integers, boolean).

Parameters:
  • dic – The intermediary dictionary representation from which the object is built.

  • e – The Encoder that is being used.

Returns:

An instance of this class initialized from the dictionary values.

get()

Create an otupy Message from MQTT Message

Parameters:

msg – An otupy Message.

Returns:

An HTTP Message

headers: Headers = None

Contains the Message metadata

set(msg: Message)

Create MQTT Message from otupy Message

Parameters:

msg – An otupy Message.

Returns:

An MQTT Message

todict(e)

Converts to dictionary

It is used to convert this object to an intermediary representation during serialization. It takes an Encoder argument that is used to recursively serialize inner data and structures (the Encoder provides standard methods for converting base types to dictionaries)..

Parameters:

e – The Encoder that is being used.

Returns:

A dictionary compliants to the Language Specification’s serialization rules.