Serialization

class someipy.serialization.Bool(value=False)

Bases: object

someipy datatype representing a boolean type transported as a single byte on the wire.

Parameters:

value (bool) –

__len__()

Return the length of the object.

Returns:

The length of the object, which is always 1.

Return type:

int

deserialize(payload)

Deserialize the payload into the value of the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

This method deserializes the payload into the value of the object. It expects the payload to be a single byte representing a boolean value. If the payload is 0, the value of the object is set to False. If the payload is 1, the value of the object is set to True. The deserialized object is then returned.

serialize()

Serialize the value of the object into bytes using the big-endian byte order.

Returns:

The serialized value of the object.

Return type:

bytes

value: bool = False
class someipy.serialization.Float32(value=0.0)

Bases: object

someipy datatype representing a 32 bit floating type.

Parameters:

value (float) –

__eq__(other)

Compare two objects for equality.

This method compares the serialized representation of the current object and the other object to determine if they are equal. It returns a Bool object indicating whether the objects are equal or not.

Parameters:

other (Any) – The object to compare with the current object.

Returns:

A Bool object indicating whether the objects are equal or not.

Return type:

Bool

__len__()

Return the length of the object.

Returns:

The length of the object, which is always 4.

Return type:

int

deserialize(payload)

Deserialize the payload into the value of the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

This method deserializes the payload into the value of the object. It expects the payload to be a 4-byte float in big-endian byte order. The deserialized value is assigned to the value attribute of the object. The deserialized object is then returned.

serialize()

Serialize the value of the object into bytes using the big-endian byte order.

Returns:

The serialized value of the object.

Return type:

bytes

This method serializes the value of the object into bytes using the big-endian byte order. It expects the value to be a float. The serialized value is returned as a bytes object.

value: float = 0.0
class someipy.serialization.Float64(value=0.0)

Bases: object

someipy datatype representing a 64 bit floating type.

Parameters:

value (float) –

__eq__(other)

Compare two objects for equality.

This method compares the serialized representation of the current object and the other object to determine if they are equal. It returns a Bool object indicating whether the objects are equal or not.

Parameters:

other (Any) – The object to compare with the current object.

Returns:

A Bool object indicating whether the objects are equal or not.

Return type:

Bool

__len__()

Return the length of the object.

Returns:

The length of the object, which is always 8.

Return type:

int

deserialize(payload)

Deserialize the payload into the value of the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

This method deserializes the payload into the value of the object. It expects the payload to be an 8-byte float in big-endian byte order. The deserialized value is assigned to the value attribute of the object. The deserialized object is then returned.

serialize()

Serialize the value of the object into bytes using the big-endian byte order.

Returns:

The serialized value of the object.

Return type:

bytes

This method serializes the value of the object into bytes using the big-endian byte order. It expects the value to be a float. The serialized value is returned as a bytes object.

value: float = 0.0
class someipy.serialization.Sint16(value=0)

Bases: object

someipy datatype representing a signed 16 bit integer on the wire.

Parameters:

value (int) –

__len__()

Return the length of the object.

Returns:

The length of the object, which is always 2.

Return type:

int

deserialize(payload)

Deserialize the payload into the value of the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

serialize()

Serialize the value of the object into bytes using the big-endian byte order.

Returns:

The serialized value of the object.

Return type:

bytes

value: int = 0
class someipy.serialization.Sint32(value=0)

Bases: object

someipy datatype representing a signed 32 bit integer on the wire.

Parameters:

value (int) –

deserialize(payload)
serialize()
Return type:

bytes

value: int = 0
class someipy.serialization.Sint64(value=0)

Bases: object

someipy datatype representing a signed 64 bit integer on the wire.

Parameters:

value (int) –

deserialize(payload)
serialize()
Return type:

bytes

value: int = 0
class someipy.serialization.Sint8(value=0)

Bases: object

someipy datatype representing a signed 8 bit integer on the wire.

Parameters:

value (int) –

__len__()

Return the length of the object.

Returns:

An integer representing the length of the object.

Return type:

int

deserialize(payload)

Deserialize the payload into the value of the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

serialize()

Serialize the value of the object into bytes using the big-endian byte order.

Returns:

The serialized value of the object.

Return type:

bytes

value: int = 0
class someipy.serialization.SomeIpDynamicSizeArray(class_reference)

Bases: Generic[T]

A datatype for a SOME/IP dynamically sized array. This type shall be used in someipy datatypes that support serialization and deserialization.

Parameters:

class_reference (Type[T]) –

__eq__(other)

Compare two SomeIpDynamicSizeArray objects for equality.

This method compares the length (number of elements) of the current array and the other array to determine if they are equal. It also compares the length of the bytes representation of the arrays. Finally, it compares the content of all elements in the arrays to check if they are equal.

Parameters:

other (SomeIpDynamicSizeArray) – The object to compare with the current object.

Returns:

True if the arrays are equal, False otherwise.

Return type:

bool

__len__()

Return the length of the object in bytes.

This method calculates the length of the object based on the number of elements in the data list and the length of each element. If the data list is empty, it returns 0. Otherwise, it returns the product of the length of the data list and the length of the first element in the data list.

Returns:

The length of the object.

Return type:

int

property data: List[T]
deserialize(payload)

Deserialize the payload into the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

This method deserializes the payload into the object. It iterates over the data list and for each element, it calls the deserialize method of that element, passing a slice of the payload corresponding to the element’s length. The deserialized values are assigned back to the corresponding elements of the data list. If the data list is empty, the method returns immediately. Finally, the deserialized object is returned.

property length_field_length
serialize()

Serialize the object into bytes by iterating over its attributes, excluding those starting with double underscores or underscores. For each attribute, it calls the serialize method of the attribute and appends the returned bytes to the output.

Returns:

The serialized representation of the object as bytes.

Return type:

bytes

class someipy.serialization.SomeIpDynamicSizeString(value='')

Bases: Generic[T]

A datatype for a SOME/IP dynamically sized string.

Parameters:

value (str) –

__eq__(other)

Compare two SomeIpDynamicSizeString objects for equality.

Parameters:

other (SomeIpDynamicSizeString) – The object to compare with the current object.

Returns:

True if the strings are equal, False otherwise.

Return type:

bool

__len__()

Return the length of the serialized string in bytes.

Returns:

The length of the string.

Return type:

int

property data: str
deserialize(payload)

Deserialize the payload into the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

This method deserializes the payload into the string. It automatically detects the encoding from the BOM at the beginning of the payload.

property encoding: str
property length_field_length
serialize()

Serialize the object into bytes by iterating over its attributes, excluding those starting with double underscores or underscores. For each attribute, it calls the serialize method of the attribute and appends the returned bytes to the output.

Returns:

The serialized representation of the object as bytes.

Return type:

bytes

class someipy.serialization.SomeIpFixedSizeArray(class_reference, size)

Bases: Generic[T]

A datatype for a SOME/IP fixed size array. This type shall be used with someipy datatypes that support serialization and deserialization.

Parameters:
  • class_reference (Type[T]) –

  • size (int) –

__eq__(other)

Compare two SomeIpFixedSizeArray objects for equality.

This method compares the length (number of elements) of the current array and the other array to determine if they are equal. It also compares the length of the bytes representation of the arrays. Finally, it compares the content of all elements in the arrays to check if they are equal.

Parameters:

other (SomeIpFixedSizeArray) – The object to compare with the current object.

Returns:

True if the arrays are equal, False otherwise.

Return type:

bool

__len__()

Return the length of the object.

This method calculates the length of the object based on the number of elements in the data list and the length of each element. If the data list is empty, it returns 0. Otherwise, it returns the product of the length of the data list and the length of the first element in the data list.

Returns:

The length of the object.

Return type:

int

deserialize(payload)

Deserialize the payload into the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

This method deserializes the payload into the object. It iterates over the data list and for each element, it calls the deserialize method of that element, passing a slice of the payload corresponding to the element’s length. The deserialized values are assigned back to the corresponding elements of the data list. If the data list is empty, the method returns immediately. Finally, the deserialized object is returned.

serialize()

Serialize the object into bytes by iterating over its attributes, excluding those starting with double underscores or underscores. For each attribute, it calls the serialize method of the attribute and appends the returned bytes to the output.

Returns:

The serialized representation of the object as bytes.

Return type:

bytes

class someipy.serialization.SomeIpFixedSizeString(size, value='')

Bases: Generic[T]

A datatype for a SOME/IP fixed size string.

Parameters:
  • size (int) –

  • value (str) –

__eq__(other)

Compare two SomeIpFixedSizeString objects for equality.

Parameters:

other (SomeIpFixedSizeArray) – The object to compare with the current object.

Returns:

True if the strings are equal, False otherwise.

Return type:

bool

__len__()

Return the length of the object on the wire in bytes. Includes the BOM and terminating ‘' character.

Returns:

The length of the object on the wire in bytes.

Return type:

int

property data: str
deserialize(payload)

Deserialize the payload into the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

This method deserializes the payload into the string. It automatically detects the encoding from the BOM at the beginning of the payload.

property encoding: str
serialize()

Serialize the object into bytes by iterating over its attributes, excluding those starting with double underscores or underscores. For each attribute, it calls the serialize method of the attribute and appends the returned bytes to the output.

Returns:

The serialized representation of the object as bytes.

Return type:

bytes

property size: int
class someipy.serialization.SomeIpPayload

Bases: object

A base class for defining a custom SOME/IP payload (“structs”). It can be recursively nested, i.e. a SomeIpPayload object may contain other SomeIpPayload objects.

__len__()

Return the length of the object.

Returns:

The length of the object.

Return type:

int

deserialize(payload)

Deserialize the payload (on wire representation) into the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

This method deserializes the payload into the object. It iterates over the attributes of the object, excluding those starting with “__”. For each attribute, it calculates the length of the corresponding value and deserializes it using the deserialize method of the value object. The deserialized values are assigned back to the corresponding attributes of the object. Finally, the deserialized object is returned.

serialize()

Serialize the object into bytes to be transported on the wire.

Returns:

The serialized representation of the object.

Return type:

bytes

class someipy.serialization.Uint16(value=0)

Bases: object

someipy datatype representing an unsigned 16 bit integer on the wire.

Parameters:

value (int) –

__len__()

Return the length of the object.

Returns:

The length of the object, which is always 2.

Return type:

int

deserialize(payload)

Deserialize the payload into the value of the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

The deserialized object.

Return type:

self

serialize()

Serialize the value of the object into bytes using the big-endian byte order.

Returns:

The serialized value of the object.

Return type:

bytes

value: int = 0
class someipy.serialization.Uint32(value=0)

Bases: object

someipy datatype representing an unsigned 32 bit integer on the wire.

Parameters:

value (int) –

deserialize(payload)
serialize()
Return type:

bytes

value: int = 0
class someipy.serialization.Uint64(value=0)

Bases: object

someipy datatype representing an unsigned 64 bit integer on the wire.

Parameters:

value (int) –

deserialize(payload)
serialize()
Return type:

bytes

value: int = 0
class someipy.serialization.Uint8(value=0)

Bases: object

someipy datatype representing an unsigned 8 bit integer on the wire.

Parameters:

value (int) –

__len__()

Return the length of the object.

Returns:

An integer representing the length of the object.

Return type:

int

deserialize(payload)

Deserialize the payload into the value of the object.

Parameters:

payload (bytes) – The payload to be deserialized.

Returns:

None

serialize()

Serialize the value of the object into bytes using the big-endian byte order.

Returns:

The serialized value of the object.

Return type:

bytes

value: int = 0
someipy.serialization.serialize(obj)

Serializes an object into bytes by iterating over its attributes, excluding those starting with double underscores or underscores. For each attribute, it calls the serialize method of the attribute and appends the returned bytes to the output.

Parameters:

obj (object) – The object to be serialized.

Returns:

The serialized representation of the object as bytes.

Return type:

bytes