forked from p15670423/monkey
Common: Add IEventSerializer
This commit is contained in:
parent
a3ddd6fb42
commit
c09adfb01b
|
@ -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
|
Loading…
Reference in New Issue