Files
api_utils_converse_v2/serialization/pickle_serializer.py
T
khushalps 0bb9553150 Squashed 'utils_v2/' content from commit 398cbc6f
git-subtree-dir: utils_v2
git-subtree-split: 398cbc6f75cdfb8ce0cca27898c3854540a208eb
2025-01-08 18:56:17 +05:30

123 lines
4.7 KiB
Python

"""
AUTHOR:
Khushal P Soonderji
DATE:
Saturday 26th Oct. 2024.
OBJECTIVE:
To provide a way to convert any input data to serialized bytes, and back.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# To work with pickling:
import pickle
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** CLASSES ***
# ***** ****
# *****************************************************************************************************************
class PickleSerializer:
def __init__(self):
"""
Use this serializer when working with custom python objects. This is meant to be fully flexible, but efficiency
is not guaranteed.
"""
pass
@staticmethod
def serialize(data):
"""
Serializes the data that is given to it.
:param data: The data to serialize.
:return: The bytes representing the data.
"""
return pickle.dumps(data)
@staticmethod
def deserialize(data):
"""
Deserializes the bytes that are given to it.
:param data: The bytes to deserialize.
:return: The data from the bytes that described it.
"""
return pickle.loads(data)
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass