diff --git a/lib/tfw/networking/__init__.py b/lib/tfw/networking/__init__.py index c5879b7..c1f3eb4 100644 --- a/lib/tfw/networking/__init__.py +++ b/lib/tfw/networking/__init__.py @@ -1,9 +1,9 @@ # Copyright (C) 2018 Avatao.com Innovative Learning Kft. # All Rights Reserved. See LICENSE file for details. -from .serialization import serialize_tfw_msg, deserialize_tfw_msg, with_deserialize_tfw_msg +from .serialization import serialize_tfw_msg, deserialize_tfw_msg +from .serialization import with_deserialize_tfw_msg, message_bytes from .zmq_connector_base import ZMQConnectorBase -# from .controller_connector import ControllerConnector # TODO: readd once controller stuff is resolved from .message_sender import MessageSender from .event_handlers.server_connector import ServerUplinkConnector as TFWServerConnector from .server.tfw_server import TFWServer diff --git a/lib/tfw/networking/serialization.py b/lib/tfw/networking/serialization.py index c28eec0..c54609b 100644 --- a/lib/tfw/networking/serialization.py +++ b/lib/tfw/networking/serialization.py @@ -67,10 +67,14 @@ def _serialize_single(data): (serialize input if it is JSON) """ if not isinstance(data, str): - data = json.dumps(data) + data = message_bytes(data) return _encode_if_needed(data) +def message_bytes(message): + return json.dumps(message, sort_keys=True).encode() + + def _deserialize_single(data): """ Try parsing input as JSON, return it as