From 9291d24a9985aecdeea62514247180422efff52f Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 11 Aug 2018 18:24:55 +0200 Subject: [PATCH] tools (common/data_format): added serialise and deserialise methods (using json for now) --- sat/tools/common/data_format.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sat/tools/common/data_format.py b/sat/tools/common/data_format.py index ad485aac..736a4838 100644 --- a/sat/tools/common/data_format.py +++ b/sat/tools/common/data_format.py @@ -21,6 +21,7 @@ #  FIXME: json may be more appropriate than manual serialising like done here from sat.core import exceptions +import json def dict2iter(name, dict_, pop=False): @@ -124,3 +125,18 @@ def getSubDict(name, dict_, sep=u"_"): continue else: yield k[len(name) + 1 :], v + +def serialise(data): + """Serialise data so it can be sent to bridge + + @return(unicode): serialised data, can be transmitted as string to the bridge + """ + return json.dumps(data, ensure_ascii=False) + +def deserialise(serialised_data): + """Deserialize data from bridge + + @param serialised_data(unicode): data to deserialise + @return(object): deserialised data + """ + return json.loads(serialised_data)