mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-06 00:01:20 +00:00
25 lines
563 B
Python
25 lines
563 B
Python
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
import json
|
|
|
|
|
|
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
|
|
|
|
|
|
def serialize_all(key, data):
|
|
return [encode_if_needed(frame) for frame in (key, json.dumps(data))]
|
|
|
|
|
|
def deserialize_all(key, data):
|
|
return decode_if_needed(key), json.loads(data)
|