3.0.ipv8.test.messaging.test_serialization ========================================== .. py:module:: 3.0.ipv8.test.messaging.test_serialization Classes ------- .. autoapisummary:: 3.0.ipv8.test.messaging.test_serialization.Short 3.0.ipv8.test.messaging.test_serialization.Byte 3.0.ipv8.test.messaging.test_serialization.Nested 3.0.ipv8.test.messaging.test_serialization.Raw 3.0.ipv8.test.messaging.test_serialization.NestedWithRaw 3.0.ipv8.test.messaging.test_serialization.TestSerializer Module Contents --------------- .. py:class:: Short(number: int) Bases: :py:obj:`3.0.ipv8.messaging.serialization.Serializable` Single unsigned short value. .. py:attribute:: format_list :value: ['H'] .. py:attribute:: number .. py:method:: to_pack_list() -> list[tuple] Serialize to a Serializer pack list. .. py:method:: from_unpack_list(number: int) -> Short :classmethod: Create a new Short object from the unpacked value. .. py:class:: Byte(byte: int) Bases: :py:obj:`3.0.ipv8.messaging.serialization.Serializable` Single unsigned char value. .. py:attribute:: format_list :value: ['B'] .. py:attribute:: byte .. py:method:: to_pack_list() -> list[tuple] Serialize to a Serializer pack list. .. py:method:: from_unpack_list(byte: int) -> Byte :classmethod: Create a new Byte object from the unpacked value. .. py:class:: Nested(byte_list: list[Byte]) Bases: :py:obj:`3.0.ipv8.messaging.serialization.Serializable` Nest a list of Byte objects. .. py:attribute:: format_list .. py:attribute:: byte_list .. py:method:: to_pack_list() -> list[tuple] Serialize to a Serializer pack list. .. py:method:: from_unpack_list(byte_list: list[Byte]) -> Nested :classmethod: Create a new Byte object from the unpacked Byte objects. .. py:class:: Raw(byte_string: bytes) Bases: :py:obj:`3.0.ipv8.messaging.serialization.Serializable` Single raw value. .. py:attribute:: format_list :value: ['raw'] .. py:attribute:: raw .. py:method:: to_pack_list() -> list[tuple] Serialize to a Serializer pack list. .. py:method:: from_unpack_list(raw_list: list[Raw]) -> Raw :classmethod: Create a new Raw object from the unpacked value. .. py:class:: NestedWithRaw(raw_list: list[list[Raw]]) Bases: :py:obj:`3.0.ipv8.messaging.serialization.Serializable` Payload that uses multiple raw values. .. py:attribute:: format_list .. py:attribute:: raw_list .. py:method:: to_pack_list() -> list[tuple] Serialize to a Serializer pack list. .. py:method:: from_unpack_list(raw_list: list[list[Raw]]) -> NestedWithRaw :classmethod: Create a new NestedWithRaw object from the unpacked Raw objects. .. py:class:: TestSerializer(methodName: str = 'runTest') Bases: :py:obj:`3.0.ipv8.test.base.TestBase` Tests related to the Serializer. .. py:method:: setUp() -> None Create a serializer. .. py:method:: check_pack_unpack(format_ser: str, format_unser: str, value: Any) -> None Pack a value using a given serializer format and unpack using another format. Asserts that the value remains unchanged. .. py:method:: test_pack_bool_true() -> None Check if 'true' booleans can be correctly packed and unpacked. .. py:method:: test_pack_bool_false() -> None Check if 'false' booleans can be correctly packed and unpacked. .. py:method:: test_pack_byte_0() -> None Check if a 0 (unsigned byte) can be correctly packed and unpacked. .. py:method:: test_pack_byte_1() -> None Check if a 1 (unsigned byte) can be correctly packed and unpacked. .. py:method:: test_pack_byte_255() -> None Check if a 255 (unsigned byte) can be correctly packed and unpacked. .. py:method:: test_pack_byte_256() -> None Check if a 256 (unsigned byte) throws a struct.error. .. py:method:: test_unpack_short_truncated() -> None Check if 1 byte string cannot be unpacked as a short. .. py:method:: test_pack_list() -> None Check if a list of shorts is correctly packed and unpacked. .. py:method:: test_get_formats() -> None Check if all reported formats contain valid packers. .. py:method:: test_add_packer() -> None Check if we can add a packer on the fly. .. py:method:: test_nested_serializable() -> None Check if we can unpack nested serializables. .. py:method:: test_serializable_byte_256() -> None Check if pack_serializable of a 256 (unsigned byte) raises a PackError. .. py:method:: test_serializable_short_from_byte() -> None Check if a unpack_serializable of a short from a byte raises a PackError. .. py:method:: test_serializable_list() -> None Check if we can (un)pack serializables easily. .. py:method:: test_serializable_list_extra_data() -> None Check if we throw an error when we have too much data to unpack. .. py:method:: test_nested_payload_list() -> None Check if we can unpack a nested serializable. .. py:method:: test_nested_serializable_raw() -> None Check if we can unpack multiple nested serializables that end with raw.