dissect.util.xmemoryview#

Module Contents#

Functions#

xmemoryview

Cast a memoryview to the specified format, including endianness.

dissect.util.xmemoryview.xmemoryview(view: bytes, format: str) memoryview | _xmemoryview#

Cast a memoryview to the specified format, including endianness.

The regular memoryview.cast() method only supports host endianness. While that should be fine 99% of the time (most of the world runs on little endian systems), we’d rather it be fine 100% of the time. This utility method ensures that by transparently converting between endianness if it doesn’t match the host endianness.

If the host endianness matches the requested endianness, this simply returns a regular memoryview.cast().

See memoryview.cast() for more details on what that actually does.

Parameters:
  • view – The bytes object or memoryview to cast.

  • format – The format to cast to in struct format syntax.

Raises:
  • ValueError – If the format is invalid.

  • TypeError – If the view is of an invalid type.