Squashed 'utils_v2/' content from commit aa76ceb
git-subtree-dir: utils_v2 git-subtree-split: aa76ceb7480020f473af5cdb44891d3ebcfc8373
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
"""
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user