# HG changeset patch # User Goffi # Date 1534004695 -7200 # Node ID 8cacf7929f3c727ee546269f5966b4bea535f503 # Parent b8600f8130ace77c2440bdb4e17e313e6740c861 tools (common/data_format): added serialise and deserialise methods (using json for now) diff -r b8600f8130ac -r 8cacf7929f3c sat/tools/common/data_format.py --- a/sat/tools/common/data_format.py Sat Aug 11 18:24:55 2018 +0200 +++ b/sat/tools/common/data_format.py Sat Aug 11 18:24:55 2018 +0200 @@ -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 @@ 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)