# Path: quantbube/utils/serializers/base.py
# class BaseSerializer(abc.ABC):
#     """
#     The base serializer class,
#     only defines the signature for loads and dumps
#     """
# 
#     @abc.abstractmethod
#     def loads(self, data, *args, **kwargs):
#         """
#         Deserialize the data
#         :param data: the structure data need to be
#         :return:
#         """
#         raise NotImplementedError()
# 
#     @abc.abstractmethod
#     def dumps(self, data, *args, **kwargs):
#         """
#         Serialize ``data`` to kinds of type
#         :param data:
#         :return:
#         """
#         raise NotImplementedError()


import datetime
import decimal
import msgpack
from dateutil import parser
from .base import BaseSerializer

    def decode_time(self, obj):
        return parser.parse(obj["str"]).time()

    def decode_decimal(self, obj):
        return decimal.Decimal(obj["str"])


class MsgPackEncoder(object):
    """
    encode the data type to the message pack format
    """

    def encode(self, obj):
        """
        :param obj:
        :return:
        """
        if type(obj) is datetime.date:
            return {"__cls__": "date", "str": obj.isoformat()}
        elif type(obj) is datetime.datetime:
            return {"__cls__": "datetime", "str": obj.isoformat()}
        elif type(obj) is datetime.time:
            return {"__cls__": "time", "str": obj.isoformat()}
        elif isinstance(obj, decimal.Decimal):
            return {"__cls__": "decimal", "str": str(obj)}
        else:
            return obj



# Path: quantbube/utils/serializers/base.py
# class BaseSerializer(abc.ABC):
#     """
#     The base serializer class,
#     only defines the signature for loads and dumps
#     """
# 
#     @abc.abstractmethod
#     def loads(self, data, *args, **kwargs):
#         """
#         Deserialize the data
#         :param data: the structure data need to be
#         :return:
#         """
#         raise NotImplementedError()
# 
#     @abc.abstractmethod
#     def dumps(self, data, *args, **kwargs):
#         """
#         Serialize ``data`` to kinds of type
#         :param data:
#         :return:
#         """
#         raise NotImplementedError()


# Path: quantbube/utils/serializers/msgpack_serializer.py
import datetime
import decimal
import msgpack
from dateutil import parser
from .base import BaseSerializer


    def decode_time(self, obj):
        return parser.parse(obj["str"]).time()

    def decode_decimal(self, obj):
        return decimal.Decimal(obj["str"])


class MsgPackEncoder(object):
    """
    encode the data type to the message pack format
    """

    def encode(self, obj):
        """
        :param obj:
        :return:
        """
        if type(obj) is datetime.date:
            return {"__cls__": "date", "str": obj.isoformat()}
        elif type(obj) is datetime.datetime:
            return {"__cls__": "datetime", "str": obj.isoformat()}
        elif type(obj) is datetime.time:
            return {"__cls__": "time", "str": obj.isoformat()}
        elif isinstance(obj, decimal.Decimal):
            return {"__cls__": "decimal", "str": str(obj)}
        else:
            return obj



class MsgPackSerializer(BaseSerializer):