Skip to content

Abstract Base Classes

mcproto.utils.abc.Serializable

Bases: ABC

Base class for any type that should be (de)serializable into/from :class:~mcproto.Buffer data.

Any class that inherits from this class and adds parameters should use the :func:~mcproto.utils.abc.define decorator.

mcproto.utils.abc.Serializable.__attrs_post_init__

__attrs_post_init__() -> None

Run the validation method after the object is initialized.

This function is responsible for conversion/transformation of given values right after initialization (often for example to convert an int initialization param into a specific enum variant)

.. note:: If you override this method, make sure to call the superclass method at some point to ensure that the validation is run.

mcproto.utils.abc.Serializable.deserialize abstractmethod classmethod

deserialize(buf: Buffer) -> Self

Construct the object from a :class:~mcproto.Buffer (transmittable sequence of bytes).

mcproto.utils.abc.Serializable.serialize

serialize() -> Buffer

Represent the object as a :class:~mcproto.Buffer (transmittable sequence of bytes).

mcproto.utils.abc.Serializable.serialize_to abstractmethod

serialize_to(buf: Buffer) -> None

Write the object to a :class:~mcproto.Buffer.

mcproto.utils.abc.Serializable.validate

validate() -> None

Validate the object's attributes, raising an exception if they are invalid.

By default, this method does nothing. Override it in your subclass to add validation logic.

.. note:: This method is called by :meth:~mcproto.utils.abc.Serializable.__attrs_post_init__