Abstract Base Classes¶
mcproto.utils.abc.Serializable
¶
Bases: ABC
Base class for any type that should be (de)serializable into/from Buffer
data.
Any class that inherits from this class and adds parameters should use the attrs.define
decorator.
mcproto.utils.abc.Serializable.__attrs_post_init__
¶
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
¶
Construct the object from a Buffer
(transmittable sequence of bytes).
mcproto.utils.abc.Serializable.serialize
¶
serialize() -> Buffer
Represent the object as a Buffer
(transmittable sequence of bytes).
mcproto.utils.abc.Serializable.serialize_to
abstractmethod
¶
serialize_to(buf: Buffer) -> None
Write the object to a Buffer
.
mcproto.utils.abc.Serializable.validate
¶
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 __attrs_post_init__