""" 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