2018-04-03 12:49:14 +00:00
|
|
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
|
2018-02-02 17:39:06 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
2018-02-02 16:30:26 +00:00
|
|
|
def encode_if_needed(value):
|
|
|
|
if isinstance(value, str):
|
|
|
|
value = value.encode('utf-8')
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
def decode_if_needed(value):
|
|
|
|
if isinstance(value, (bytes, bytearray)):
|
|
|
|
value = value.decode('utf-8')
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
2018-02-08 14:08:19 +00:00
|
|
|
def serialize_all(key, data):
|
|
|
|
return [encode_if_needed(frame) for frame in (key, json.dumps(data))]
|
2018-02-02 16:30:26 +00:00
|
|
|
|
|
|
|
|
2018-02-08 14:08:19 +00:00
|
|
|
def deserialize_all(key, data):
|
|
|
|
return decode_if_needed(key), json.loads(data)
|