Mercurial > libervia-backend
diff sat/tools/common/data_format.py @ 2656:8cacf7929f3c
tools (common/data_format): added serialise and deserialise methods (using json for now)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 11 Aug 2018 18:24:55 +0200 |
parents | 56f94936df1e |
children | fcc945537d5f |
line wrap: on
line diff
--- 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)