File: base.py

package info (click to toggle)
python-parsl 2025.01.13%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,072 kB
  • sloc: python: 23,817; makefile: 349; sh: 276; ansic: 45
file content (38 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
from abc import abstractmethod
from functools import cached_property
from typing import Any

logger = logging.getLogger(__name__)


class SerializerBase:
    """ Adds shared functionality for all serializer implementations
    """

    @cached_property
    def identifier(self) -> bytes:
        """Compute identifier used in serialization header.
        This will be used to indicate in byte streams that this class should
        be used for deserialization.
       Serializers that use identifiers that don't align with the way this is
        computed (such as the default concretes.py implementations) should
        override this property with their own identifier.
        Returns
        -------
        identifier : bytes
        """
        t = type(self)
        m = bytes(t.__module__, encoding="utf-8")
        c = bytes(t.__name__, encoding="utf-8")
        return m + b' ' + c

    @abstractmethod
    def serialize(self, data: Any) -> bytes:
        pass

    @abstractmethod
    def deserialize(self, payload: bytes) -> Any:
        pass