aea.protocols.base

This module contains the base message and serialization definition.

Message

class Message()

This class implements a message.

__init__

 | __init__(body: Optional[Dict] = None, **kwargs)

Initialize a Message object.

Arguments:

  • body: the dictionary of values to hold.
  • kwargs: any additional value to add to the body. It will overwrite the body values.

counterparty

 | @counterparty.setter
 | counterparty(counterparty: Address) -> None

Set the counterparty of the message.

is_incoming

 | @is_incoming.setter
 | is_incoming(is_incoming: bool) -> None

Set the is_incoming of the message.

body

 | @body.setter
 | body(body: Dict) -> None

Set the body of hte message.

Arguments:

  • body: the body.

Returns:

None

message_id

 | @property
 | message_id() -> int

Get the message id.

set

 | set(key: str, value: Any) -> None

Set key and value pair.

Arguments:

  • key: the key.
  • value: the value.

Returns:

None

get

 | get(key: str) -> Optional[Any]

Get value for key.

unset

 | unset(key: str) -> None

Unset valye for key.

is_set

 | is_set(key: str) -> bool

Check value is set for key.

__eq__

 | __eq__(other)

Compare with another object.

__str__

 | __str__()

Get the string representation of the message.

Encoder

class Encoder(ABC)

Encoder interface.

encode

 | @abstractmethod
 | encode(msg: Message) -> bytes

Encode a message.

Arguments:

  • msg: the message to be encoded.

Returns:

the encoded message.

Decoder

class Decoder(ABC)

Decoder interface.

decode

 | @abstractmethod
 | decode(obj: bytes) -> Message

Decode a message.

Arguments:

  • obj: the sequence of bytes to be decoded.

Returns:

the decoded message.

Serializer

class Serializer(Encoder,  Decoder,  ABC)

The implementations of this class defines a serialization layer for a protocol.

ProtobufSerializer

class ProtobufSerializer(Serializer)

Default Protobuf serializer.

It assumes that the Message contains a JSON-serializable body.

encode

 | encode(msg: Message) -> bytes

Encode a message into bytes using Protobuf.

decode

 | decode(obj: bytes) -> Message

Decode bytes into a message using Protobuf.

JSONSerializer

class JSONSerializer(Serializer)

Default serialization in JSON for the Message object.

It assumes that the Message contains a JSON-serializable body.

encode

 | encode(msg: Message) -> bytes

Encode a message into bytes using JSON format.

Arguments:

  • msg: the message to be encoded.

Returns:

the serialized message.

decode

 | decode(obj: bytes) -> Message

Decode bytes into a message using JSON.

Arguments:

  • obj: the serialized message.

Returns:

the decoded message.

Protocol

class Protocol(Component)

This class implements a specifications for a protocol.

It includes a serializer to encode/decode a message.

__init__

 | __init__(configuration: ProtocolConfig, serializer: Serializer)

Initialize the protocol manager.

Arguments:

  • configuration: the protocol configurations.
  • serializer: the serializer.

serializer

 | @property
 | serializer() -> Serializer

Get the serializer.

from_dir

 | @classmethod
 | from_dir(cls, directory: str) -> "Protocol"

Load the protocol from a directory.

Arguments:

  • directory: the directory to the skill package.

Returns:

the protocol object.

from_config

 | @classmethod
 | from_config(cls, configuration: ProtocolConfig) -> "Protocol"

Load the protocol from configuration.

Arguments:

  • configuration: the protocol configuration.

Returns:

the protocol object.