Common: Add IEventSerializer

This commit is contained in:
Shreya Malviya 2022-08-17 17:57:28 +05:30
parent a3ddd6fb42
commit c09adfb01b
1 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,34 @@
from abc import ABC, abstractmethod
from typing import Dict, List, Type, Union
from common.events import AbstractEvent
JSONSerializable = Union[
Dict[str, "JSONSerializable"], List["JSONSerializable"], int, str, float, bool, Type[None]
]
class IEventSerializer(ABC):
"""
Manages serialization and deserialization of events
"""
@abstractmethod
def serialize(self, event: AbstractEvent) -> JSONSerializable:
"""
Serializes an event
:param event: Event to serialize
:return: Serialized event
"""
pass
@abstractmethod
def deserialize(self, serialized_event: JSONSerializable) -> AbstractEvent:
"""
Deserializes an event
:param serialized_event: Serialized vent to deserialize
:return: Deserialized event
"""
pass