2.12.ipv8.test.messaging.test_serialization

Module Contents

Classes

class 2.12.ipv8.test.messaging.test_serialization.Short(number: int)

Bases: 2.12.ipv8.messaging.serialization.Serializable

Single unsigned short value.

format_list = ['H']
to_pack_list() list[tuple]

Serialize to a Serializer pack list.

classmethod from_unpack_list(number: int) Short

Create a new Short object from the unpacked value.

class 2.12.ipv8.test.messaging.test_serialization.Byte(byte: int)

Bases: 2.12.ipv8.messaging.serialization.Serializable

Single unsigned char value.

format_list = ['B']
to_pack_list() list[tuple]

Serialize to a Serializer pack list.

classmethod from_unpack_list(byte: int) Byte

Create a new Byte object from the unpacked value.

class 2.12.ipv8.test.messaging.test_serialization.Nested(byte_list: list[Byte])

Bases: 2.12.ipv8.messaging.serialization.Serializable

Nest a list of Byte objects.

format_list = [None]
to_pack_list() list[tuple]

Serialize to a Serializer pack list.

classmethod from_unpack_list(byte_list: list[Byte]) Nested

Create a new Byte object from the unpacked Byte objects.

class 2.12.ipv8.test.messaging.test_serialization.TestSerializer(methodName: str = 'runTest')

Bases: 2.12.ipv8.test.base.TestBase

Tests related to the Serializer.

setUp() None

Create a serializer.

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.

test_pack_bool_true() None

Check if ‘true’ booleans can be correctly packed and unpacked.

test_pack_bool_false() None

Check if ‘false’ booleans can be correctly packed and unpacked.

test_pack_byte_0() None

Check if a 0 (unsigned byte) can be correctly packed and unpacked.

test_pack_byte_1() None

Check if a 1 (unsigned byte) can be correctly packed and unpacked.

test_pack_byte_255() None

Check if a 255 (unsigned byte) can be correctly packed and unpacked.

test_pack_byte_256() None

Check if a 256 (unsigned byte) throws a struct.error.

test_unpack_short_truncated() None

Check if 1 byte string cannot be unpacked as a short.

test_pack_list() None

Check if a list of shorts is correctly packed and unpacked.

test_get_formats() None

Check if all reported formats contain valid packers.

test_add_packer() None

Check if we can add a packer on the fly.

test_nested_serializable() None

Check if we can unpack nested serializables.

test_serializable_byte_256() None

Check if pack_serializable of a 256 (unsigned byte) raises a PackError.

test_serializable_short_from_byte() None

Check if a unpack_serializable of a short from a byte raises a PackError.

test_serializable_list() None

Check if we can (un)pack serializables easily.

test_serializable_list_extra_data() None

Check if we throw an error when we have too much data to unpack.

test_nested_payload_list() None

Check if we can unpack a nested serializable.