-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
We need to add support for binary (de)/serialization to compas_eve messages using compas_pb
using the following specs:
- A
Transport
should accept a new optional parametercodec
. By default, ifNone
is specified,compas_eve
should use its ownJsonMessageCodec
. - Codecs are classes that know how to encode and decode a message down to a different representation. The default one being
JSON
, which is provided byJsonMessageCodec
. Also add an abstract classMessageCodec
- Currently, the implementations of transport has a call to
topic._message_to_json(..)
andtopic._message_from_json(..)
to encode and decode. This should change to betopic._message_to_data(..)
and thenself.codec.encode(..)
(and the respective decoding part). - A new codec should be added, called
ProtobufMessageCodec
to support binary serialization. - The requirement to
compas_pb
should be optional, so, ifcompas_pb
is not installed, the codec is simply going to report it cannot be used becausecompas_pb
needs to be installed. - Please take into account that there are 3 cases of messages: a
Message
instance, any object with__data__
(ie. a COMPAS data object), and anything that can be casted to adict
. This roughly means this method should handle most things. However,compas_pb
already handles COMPAS data objects and fallback to dictionary, so the last two options are probably the same.
def _message_to_data(self, message):
"""Convert a message to a data representation ready to be encoded.
Normally, this method expects sub-classes of Message as input.
However, it can deal with regular dictionaries as well as classes
implementing the COMPAS data framework.
"""
try:
data = message.data
except (KeyError, AttributeError):
try:
data = message.__data__
except (KeyError, AttributeError):
data = dict(message)
return data
- In the process, please remove the
mqtt_cli
implementation, and all support for IronPython, because we will bump the major and forget about Rhino 7.
Copilot
Metadata
Metadata
Assignees
Labels
No labels