Skip to content

Interpreter

This module contains the Interpreter abstract class and its implementation JSONInterpreter.

CLASS DESCRIPTION
Interpreter

Abstract class for encoding and decoding messages.

JSONInterpreter

Class for encoding and decoding messages in JSON format.

Documentation last updated: 2025-06-11

Interpreter

Interpreter()

Abstract class for encoding and decoding messages.

METHOD DESCRIPTION
decodeRequest

Decode a request message into a command dictionary.

encodeData

Encode data into a message.

encodeRequest

Encode a command dictionary into a request message.

decodeData

Decode a message into data.

decodeData staticmethod

decodeData(packet: str | bytes) -> dict[str, Any]

Decode a message into data.

PARAMETER DESCRIPTION
packet

message to be decoded

TYPE: str | bytes

RETURNS DESCRIPTION
dict[str, Any]

dict[str, Any]: decoded data

decodeRequest staticmethod

decodeRequest(packet: str | bytes) -> dict[str, Any]

Decode a request message into a command dictionary.

PARAMETER DESCRIPTION
packet

request message to be decoded

TYPE: str | bytes

RETURNS DESCRIPTION
dict[str, Any]

dict[str, Any]: command dictionary

encodeData staticmethod

encodeData(data: Any) -> bytes

Encode data into a message.

PARAMETER DESCRIPTION
data

data to be encoded

TYPE: Any

RETURNS DESCRIPTION
bytes

encoded message in bytes

TYPE: bytes

encodeRequest staticmethod

encodeRequest(command: Mapping[str, Any]) -> bytes

Encode a command dictionary into a request message.

PARAMETER DESCRIPTION
command

command dictionary

TYPE: Mapping[str, Any]

RETURNS DESCRIPTION
bytes

request message in bytes

TYPE: bytes

JSONInterpreter

JSONInterpreter()

Bases: Interpreter

Class for encoding and decoding messages in JSON format.

METHOD DESCRIPTION
decodeRequest

Decode a request message into a command dictionary.

encodeData

Encode data into a message.

encodeRequest

Encode a command dictionary into a request message.

decodeData

Decode a message into data

decodeData staticmethod

decodeData(packet: str | bytes) -> dict[str, Any]

Decode a message into data.

PARAMETER DESCRIPTION
packet

message to be decoded

TYPE: str | bytes

RETURNS DESCRIPTION
dict[str, Any]

dict[str, Any]: decoded data

decodeRequest staticmethod

decodeRequest(packet: str | bytes) -> dict[str, Any]

Decode a request message into a command dictionary.

PARAMETER DESCRIPTION
packet

request message

TYPE: str | bytes

RETURNS DESCRIPTION
dict[str, Any]

dict[str, Any]: command dictionary

encodeData staticmethod

encodeData(data: Mapping[str, Any]) -> bytes

Encode data into a message.

PARAMETER DESCRIPTION
data

data to be encoded

TYPE: Mapping[str, Any]

RETURNS DESCRIPTION
bytes

encoded message

TYPE: bytes

encodeRequest staticmethod

encodeRequest(command: Mapping[str, Any]) -> bytes

Encode a command dictionary into a request message.

PARAMETER DESCRIPTION
command

command dictionary

TYPE: Mapping[str, Any]

RETURNS DESCRIPTION
bytes

request message

TYPE: bytes