Skip to main content

base

pymusas.base

[SOURCE]


Base classes for custom classes to inherit from.

Serialise​

class Serialise(ABC)

An abstract class that defines the basic methods, to_bytes, and from_bytes that is required for all Serialises.

to_bytes​

class Serialise(ABC):
| ...
| @abstractmethod
| def to_bytes() -> bytes

Serialises the class to a bytestring.

Returns¶​

  • bytes

from_bytes​

class Serialise(ABC):
| ...
| @staticmethod
| @abstractmethod
| def from_bytes(bytes_data: bytes) -> "Serialise"

Loads the class from the given bytestring and returns it.

Parameters¶​

  • bytes_data : bytes
    The bytestring to load.

Returns¶​

serialise_object_to_bytes​

class Serialise(ABC):
| ...
| @staticmethod
| def serialise_object_to_bytes(
| serialise_object: "Serialise"
| ) -> bytes

Given a serialise object it will serialise it to a bytestring.

This function in comparison to calling to_bytes on the serialise object saves meta data about what class it is so that when loading the bytes data later on you will know which class saved the data, this would not happen if you called to_bytes on the custom object.

Parameters¶​

  • serialise_object : Serialise
    The serialise object, of type Serialise, to serialise.

Returns¶​

  • bytes

serialise_object_from_bytes​

class Serialise(ABC):
| ...
| @staticmethod
| def serialise_object_from_bytes(
| bytes_data: bytes
| ) -> "Serialise"

Loads the serialise object from the given bytestring and return it. This is the inverse of function of serialise_object_to_bytes.

Parameters¶​

  • bytes_data : bytes
    The bytestring to load.

Returns¶​

  • Serialise

serialise_object_list_to_bytes​

class Serialise(ABC):
| ...
| @staticmethod
| def serialise_object_list_to_bytes(
| serialise_objects: Iterable["Serialise"]
| ) -> bytes

Serialises an Iterable of serialise objects in the same way as serialise_object_to_bytes.

Parameters¶​

  • serialise_objects : Iterable[Serialise]
    The serialise objects, of type Serialise, to serialise.

Returns¶​

  • bytes

serialise_object_list_from_bytes​

class Serialise(ABC):
| ...
| @staticmethod
| def serialise_object_list_from_bytes(
| bytes_data: bytes
| ) -> Iterable["Serialise"]

Loads the serialise objects from the given bytestring and return them. This is the inverse of function of serialise_object_list_to_bytes.

Parameters¶​

  • bytes_data : bytes
    The bytestring to load.

Returns¶​

  • Iterable[Serialise]