Skip to content

Add support for compas_pb serialization #22

@gonzalocasas

Description

@gonzalocasas

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 parameter codec. By default, if None is specified, compas_eve should use its own JsonMessageCodec.
  • 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 by JsonMessageCodec. Also add an abstract class MessageCodec
  • Currently, the implementations of transport has a call to topic._message_to_json(..) and topic._message_from_json(..) to encode and decode. This should change to be topic._message_to_data(..) and then self.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, if compas_pb is not installed, the codec is simply going to report it cannot be used because compas_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 a dict. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions