mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 16:31:21 +00:00
22 lines
468 B
Python
22 lines
468 B
Python
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(anchor, message):
|
|
return [encode_if_needed(a) for a in (anchor, json.dumps(message))]
|
|
|
|
|
|
def deserialize_all(anchor, message):
|
|
return decode_if_needed(anchor), json.loads(message)
|