tools (common/data_format): added serialise and deserialise methods (using json for now)
This commit is contained in:
parent
64d502958f
commit
9291d24a99
1 changed files with 16 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue