Mark old serialization methods as module internal

This commit is contained in:
Kristóf Tóth 2018-04-13 20:29:02 +02:00
parent 499b575adf
commit 3c12b5503e
3 changed files with 10 additions and 11 deletions

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft. # Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details. # All Rights Reserved. See LICENSE file for details.
from .serialization import decode_if_needed, encode_if_needed, serialize_all, deserialize_all
from .serialization import serialize_tfw_msg, deserialize_tfw_msg from .serialization import serialize_tfw_msg, deserialize_tfw_msg
from .zmq_connector_base import ZMQConnectorBase from .zmq_connector_base import ZMQConnectorBase
from .controller_connector import ControllerConnector # from .controller_connector import ControllerConnector # TODO: readd once controller stuff is resolved
from .message_sender import MessageSender from .message_sender import MessageSender
from .event_handlers.server_connector import ServerUplinkConnector as TFWServerConnector from .event_handlers.server_connector import ServerUplinkConnector as TFWServerConnector
from .server.tfw_server import TFWServer from .server.tfw_server import TFWServer

View File

@ -25,41 +25,41 @@ import json
def serialize_tfw_msg(message): def serialize_tfw_msg(message):
return serialize_all(message['key'], message) return _serialize_all(message['key'], message)
def deserialize_tfw_msg(*args): def deserialize_tfw_msg(*args):
return deserialize_all(*args)[1] return _deserialize_all(*args)[1]
def serialize_all(*args): def _serialize_all(*args):
return tuple(_serialize_single(arg) for arg in args) return tuple(_serialize_single(arg) for arg in args)
def deserialize_all(*args): def _deserialize_all(*args):
return tuple(_deserialize_single(arg) for arg in args) return tuple(_deserialize_single(arg) for arg in args)
def _serialize_single(data): def _serialize_single(data):
if not isinstance(data, str): if not isinstance(data, str):
data = json.dumps(data) data = json.dumps(data)
return encode_if_needed(data) return _encode_if_needed(data)
def _deserialize_single(data): def _deserialize_single(data):
try: try:
return json.loads(data) return json.loads(data)
except ValueError: except ValueError:
return decode_if_needed(data) return _decode_if_needed(data)
def encode_if_needed(value): def _encode_if_needed(value):
if isinstance(value, str): if isinstance(value, str):
value = value.encode('utf-8') value = value.encode('utf-8')
return value return value
def decode_if_needed(value): def _decode_if_needed(value):
if isinstance(value, (bytes, bytearray)): if isinstance(value, (bytes, bytearray)):
value = value.decode('utf-8') value = value.decode('utf-8')
return value return value

View File

@ -4,4 +4,4 @@
from .event_handler_connector import EventHandlerConnector, EventHandlerUplinkConnector, EventHandlerDownlinkConnector from .event_handler_connector import EventHandlerConnector, EventHandlerUplinkConnector, EventHandlerDownlinkConnector
from .tfw_server import TFWServer from .tfw_server import TFWServer
from .zmq_websocket_handler import ZMQWebSocketProxy from .zmq_websocket_handler import ZMQWebSocketProxy
from .controller_responder import ControllerResponder # from .controller_responder import ControllerResponder # TODO: readd once controller stuff is resolved