Fix broken ZMQ messages

This commit is contained in:
R. Richard 2020-05-07 09:47:35 +02:00
parent f374cb7e46
commit dc76f1b732

View File

@ -42,7 +42,8 @@ def deserialize_tfw_msg(*args):
""" """
Return message from TFW multipart data Return message from TFW multipart data
""" """
return _deserialize_all(*args)[1] envelope = _deserialize_all(*args)
return _repair_if_needed(envelope)
def _serialize_all(*args): def _serialize_all(*args):
@ -84,6 +85,18 @@ def _deserialize_single(data):
return _decode_if_needed(data) return _decode_if_needed(data)
def _repair_if_needed(envelope):
"""
Quick fix for broken messages received from separate processes.
"""
if len(envelope) == 2:
return envelope[1]
for part in envelope:
if isinstance(part, dict):
return part
return {}
def _encode_if_needed(value): def _encode_if_needed(value):
""" """
Return input as bytes Return input as bytes