uds.utilities.bytes_operations

Module with bytes list operations implementation.

Module Contents

Classes

Endianness

Endianness values definitions.

Functions

bytes_list_to_int(bytes_list[, endianness])

Convert a list of bytes to integer value.

int_to_bytes_list(int_value[, list_size, endianness])

Convert integer value to a list of bytes.

class uds.utilities.bytes_operations.Endianness[source]

Bases: aenum.StrEnum, uds.utilities.enums.ValidatedEnum

Inheritance diagram of uds.utilities.bytes_operations.Endianness

Endianness values definitions.

Endianness determines order of bytes in a bytes sequence.

Initialize self. See help(type(self)) for accurate signature.

LITTLE_ENDIAN: Endianness = 'little'

Little Endian stores the most significant byte at the largest memory address and the least significant byte at the smallest.

BIG_ENDIAN: Endianness = 'big'

Big Endian stores the most significant byte at the smallest memory address and the least significant byte at the largest.

uds.utilities.bytes_operations.bytes_list_to_int(bytes_list, endianness=Endianness.BIG_ENDIAN)[source]

Convert a list of bytes to integer value.

Parameters:
  • bytes_list (uds.utilities.common_types.RawBytesAlias) – List of bytes to convert.

  • endianness (Endianness) – Order of bytes to use.

Returns:

The integer value represented by provided list of bytes.

Return type:

int

uds.utilities.bytes_operations.int_to_bytes_list(int_value, list_size=None, endianness=Endianness.BIG_ENDIAN)[source]

Convert integer value to a list of bytes.

Parameters:
  • int_value (int) – Integer value to convert.

  • list_size (Optional[int]) – Size of the output list. Use None to use the smallest possible list size.

  • endianness (Endianness) – Order of bytes to use.

Raises:
  • TypeError – At least one provided value has invalid type.

  • ValueError – At least one provided value is out of range.

  • InconsistentArgumentsError – Provided value of list_size is too small to contain entire int_value.

  • NotImplementedError – There is missing implementation for the provided Endianness. Please create an issue in our Issues Tracking System with detailed description if you face this error.

Returns:

The value of bytes list that represents the provided integer value.

Return type:

uds.utilities.common_types.RawBytesListAlias