signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def extend(self, iterable):
<EOL>if is_sequence(iterable):<EOL><INDENT>self._data.extend(iterable)<EOL><DEDENT>elif is_structure(iterable):<EOL><INDENT>members = [item for item in iterable.values()]<EOL>self._data.extend(members)<EOL><DEDENT>elif is_field(iterable):<EOL><INDENT>self._data.extend([iterable])<EOL><DEDENT>elif isinstance(iterable, (...
Extends the `Sequence` by appending items from the *iterable*. :param iterable: any *iterable* that contains items of :class:`Structure`, :class:`Sequence`, :class:`Array` or :class:`Field` instances. If the *iterable* is one of these instances itself then the *iterable* itself ...
f12145:c3:m16
@nested_option()<EOL><INDENT>def read_from(self, provider, **options):<DEDENT>
for item in iter(self):<EOL><INDENT>if is_mixin(item):<EOL><INDENT>item.read_from(provider, **options)<EOL><DEDENT><DEDENT>
All :class:`Pointer` fields in the `Sequence` read the necessary number of bytes from the data :class:`Provider` for their referenced :attr:`~Pointer.data` object. Null pointer are ignored. :param Provider provider: data :class:`Provider`. :keyword bool nested: if ``True`` all :class:`P...
f12145:c3:m17
@byte_order_option()<EOL><INDENT>@nested_option()<EOL>def deserialize(self, buffer=bytes(), index=Index(), **options):<DEDENT>
for item in iter(self):<EOL><INDENT>index = item.deserialize(buffer, index, **options)<EOL><DEDENT>return index<EOL>
De-serializes the `Sequence` from the byte *buffer* starting at the begin of the *buffer* or with the given *index* by mapping the bytes to the :attr:`~Field.value` for each :class:`Field` in the `Sequence` in accordance with the decoding *byte order* for the de-serialization and the dec...
f12145:c3:m18
@byte_order_option()<EOL><INDENT>@nested_option()<EOL>def serialize(self, buffer=bytearray(), index=Index(), **options):<DEDENT>
for item in iter(self):<EOL><INDENT>index = item.serialize(buffer, index, **options)<EOL><DEDENT>return index<EOL>
Serializes the `Sequence` to the byte *buffer* starting at begin of the *buffer* or with the given *index* by mapping the :attr:`~Field.value` for each :class:`Field` in the `Sequence` to the byte *buffer* in accordance with the encoding *byte order* for the serialization and the encodin...
f12145:c3:m19
@nested_option()<EOL><INDENT>def index_fields(self, index=Index(), **options):<DEDENT>
for name, item in enumerate(self):<EOL><INDENT>if is_container(item):<EOL><INDENT>index = item.index_fields(index, **options)<EOL><DEDENT>elif is_pointer(item) and get_nested(options):<EOL><INDENT>index = item.index_field(index)<EOL>item.index_data()<EOL><DEDENT>elif is_field(item):<EOL><INDENT>index = item.index_field...
Indexes all fields in the `Sequence` starting with the given *index* and returns the :class:`Index` after the last :class:`Field` in the `Sequence`. :param Index index: start :class:`Index` for the first :class:`Field` in the `Sequence`. :keyword bool nested: if ``True`` all...
f12145:c3:m20
def container_size(self):
length = <NUM_LIT:0><EOL>for name, item in enumerate(self):<EOL><INDENT>if is_container(item):<EOL><INDENT>byte_length, bit_length = item.container_size()<EOL>length += bit_length + byte_length * <NUM_LIT:8><EOL><DEDENT>elif is_field(item):<EOL><INDENT>length += item.bit_size<EOL><DEDENT>else:<EOL><INDENT>raise MemberT...
Returns the accumulated bit size of all fields in the `Sequence` as a tuple in the form of ``(number of bytes, remaining number of bits)``.
f12145:c3:m21
def first_field(self):
for name, item in enumerate(self):<EOL><INDENT>if is_container(item):<EOL><INDENT>field = item.first_field()<EOL>if field is not None:<EOL><INDENT>return field<EOL><DEDENT><DEDENT>elif is_field(item):<EOL><INDENT>return item<EOL><DEDENT>else:<EOL><INDENT>raise MemberTypeError(self, item, name)<EOL><DEDENT><DEDENT>retur...
Returns the first :class:`Field` in the `Sequence` or ``None`` for an empty `Sequence`.
f12145:c3:m22
def initialize_fields(self, content):
for name, pair in enumerate(zip(self, content)):<EOL><INDENT>item, value = pair<EOL>if is_mixin(item):<EOL><INDENT>item.initialize_fields(value)<EOL><DEDENT>elif is_field(item):<EOL><INDENT>item.value = value<EOL><DEDENT>else:<EOL><INDENT>raise MemberTypeError(self, item, name)<EOL><DEDENT><DEDENT>
Initializes the :class:`Field` items in the `Sequence` with the *values* in the *content* list. :param list content: a list contains the :class:`Field` values for each item in the `Sequence`.
f12145:c3:m23
@nested_option()<EOL><INDENT>def view_fields(self, *attributes, **options):<DEDENT>
items = list()<EOL>for index, item in enumerate(self):<EOL><INDENT>if is_container(item):<EOL><INDENT>items.append(item.view_fields(*attributes, **options))<EOL><DEDENT>elif is_pointer(item) and get_nested(options):<EOL><INDENT>items.append(item.view_fields(*attributes, **options))<EOL><DEDENT>elif is_field(item):<EOL>...
Returns a list with the selected field *attribute* or a list with the dictionaries of the selected field *attributes* for each :class:`Field` *nested* in the `Sequence`. The *attributes* of each :class:`Field` for containers *nested* in the `Sequence` are viewed as well (chained method ...
f12145:c3:m24
@nested_option()<EOL><INDENT>def field_items(self, path=str(), **options):<DEDENT>
items = list()<EOL>for index, item in enumerate(self):<EOL><INDENT>if path:<EOL><INDENT>item_path = "<STR_LIT>".format(path, str(index))<EOL><DEDENT>else:<EOL><INDENT>item_path = "<STR_LIT>".format(str(index))<EOL><DEDENT>if is_container(item):<EOL><INDENT>for field_item in item.field_items(item_path, **options):<EOL><...
Returns a **flatten** list of ``('field path', field item)`` tuples for each :class:`Field` *nested* in the `Sequence`. :param str path: field path of the `Sequence`. :keyword bool nested: if ``True`` all :class:`Pointer` fields in the :attr:`~Pointer.data` objects of all :class:`Po...
f12145:c3:m25
@nested_option(True)<EOL><INDENT>def describe(self, name=str(), **options):<DEDENT>
members = list()<EOL>metadata = OrderedDict()<EOL>metadata['<STR_LIT:class>'] = self.__class__.__name__<EOL>metadata['<STR_LIT:name>'] = name if name else self.__class__.__name__<EOL>metadata['<STR_LIT:size>'] = len(self)<EOL>metadata['<STR_LIT:type>'] = self.item_type.name<EOL>metadata['<STR_LIT>'] = members<EOL>for m...
Returns the **metadata** of the `Sequence` as an :class:`ordered dictionary <collections.OrderedDict>`. .. code-block:: python metadata = { 'class': self.__class__.__name__, 'name': name if name else self.__class__.__name__, 'size': len(self)...
f12145:c3:m26
def append(self):
super().append(self.__create__())<EOL>
Appends a new *array element* to the `Array`.
f12145:c4:m2
def insert(self, index):
super().insert(index, self.__create__())<EOL>
Inserts a new *array element* before the *index* of the `Array`. :param int index: `Array` index.
f12145:c4:m3
def resize(self, capacity):
count = max(int(capacity), <NUM_LIT:0>) - len(self)<EOL>if count == <NUM_LIT:0>:<EOL><INDENT>pass<EOL><DEDENT>elif -count == len(self):<EOL><INDENT>self.clear()<EOL><DEDENT>elif count > <NUM_LIT:0>:<EOL><INDENT>for i in range(count):<EOL><INDENT>self.append()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for i in range(abs(cou...
Re-sizes the `Array` by appending new *array elements* or removing *array elements* from the end. :param int capacity: new capacity of the `Array` in number of *array elements*.
f12145:c4:m4
def initialize_fields(self, content):
if isinstance(content, (list, tuple)):<EOL><INDENT>capacity = len(content)<EOL>for i in range(<NUM_LIT:0>, len(self), capacity):<EOL><INDENT>for name, pair in enumerate(zip(self[i:i + capacity],<EOL>content),<EOL>start=i):<EOL><INDENT>item, value = pair<EOL>if is_mixin(item):<EOL><INDENT>item.initialize_fields(value)<E...
Initializes the :class:`Field` elements in the `Array` with the *values* in the *content* list. If the *content* list is shorter than the `Array` then the *content* list is used as a rotating fill pattern for the :class:`Field` elements in the `Array`. :param list content: a li...
f12145:c4:m5
@property<EOL><INDENT>def alignment(self):<DEDENT>
return Alignment(self._align_to_byte_size, self._align_to_bit_offset)<EOL>
Returns the :class:`Alignment` of the `Field` (read-only).
f12145:c5:m3
@property<EOL><INDENT>def bit_size(self):<DEDENT>
return self._bit_size<EOL>
Returns the size of the `Field` in bits (read-only).
f12145:c5:m4
@property<EOL><INDENT>def byte_order(self):<DEDENT>
return self._byte_order<EOL>
:class:`Byteorder` used to decode and encode the :attr:`value` of the `Field`.
f12145:c5:m5
@property<EOL><INDENT>def index(self):<DEDENT>
return self._index<EOL>
:class:`Index` of the `Field`.
f12145:c5:m7
@property<EOL><INDENT>def name(self):<DEDENT>
return self.item_type.name.capitalize() + str(self.bit_size)<EOL>
Returns the type name of the `Field` (read-only).
f12145:c5:m9
@property<EOL><INDENT>def value(self):<DEDENT>
return self._value<EOL>
Field value.
f12145:c5:m10
@staticmethod<EOL><INDENT>def is_bit():<DEDENT>
return False<EOL>
Returns ``False``.
f12145:c5:m12
@staticmethod<EOL><INDENT>def is_bool():<DEDENT>
return False<EOL>
Returns ``False``.
f12145:c5:m13
@staticmethod<EOL><INDENT>def is_decimal():<DEDENT>
return False<EOL>
Returns ``False``.
f12145:c5:m14
@staticmethod<EOL><INDENT>def is_float():<DEDENT>
return False<EOL>
Returns ``False``.
f12145:c5:m15
@staticmethod<EOL><INDENT>def is_pointer():<DEDENT>
return False<EOL>
Returns ``False``.
f12145:c5:m16
@staticmethod<EOL><INDENT>def is_stream():<DEDENT>
return False<EOL>
Returns ``False``.
f12145:c5:m17
@staticmethod<EOL><INDENT>def is_string():<DEDENT>
return False<EOL>
Returns ``False``.
f12145:c5:m18
@abc.abstractmethod<EOL><INDENT>@byte_order_option()<EOL>def unpack(self, buffer=bytes(), index=Index(), **options):<DEDENT>
<EOL>return None<EOL>
Unpacks the field :attr:`value` from the *buffer* at the given *index* in accordance with the decoding *byte order* for the de-serialization and the :attr:`byte_order` and :attr:`alignment` of the `Field`. The specific decoding :attr:`byte_order` of the `Field` overrules the dec...
f12145:c5:m19
@abc.abstractmethod<EOL><INDENT>@byte_order_option()<EOL>def pack(self, buffer=bytearray(), **options):<DEDENT>
<EOL>return bytes()<EOL>
Packs the field :attr:`value` to the *buffer* at the given *index* in accordance with the encoding *byte order* for the serialization and the :attr:`byte_order` and :attr:`alignment` of the `Field`. The specific encoding :attr:`byte_order` of the `Field` overrules the encoding *byte ord...
f12145:c5:m20
@byte_order_option()<EOL><INDENT>@nested_option()<EOL>def deserialize(self, buffer=bytes(), index=Index(), **options):<DEDENT>
self.index = index<EOL>self._value = self.unpack(buffer, index, **options)<EOL>return self.index_field(index)<EOL>
De-serializes the `Field` from the byte *buffer* starting at the begin of the *buffer* or with the given *index* by unpacking the bytes to the :attr:`value` of the `Field` in accordance with the decoding *byte order* for the de-serialization and the decoding :attr:`byte_order` of the `Fi...
f12145:c5:m21
@byte_order_option()<EOL><INDENT>@nested_option()<EOL>def serialize(self, buffer=bytearray(), index=Index(), **options):<DEDENT>
self.index = index<EOL>buffer += self.pack(buffer, **options)<EOL>return self.index_field(index)<EOL>
Serializes the `Field` to the byte *buffer* starting at the begin of the *buffer* or with the given *index* by packing the :attr:`value` of the `Field` to the byte *buffer* in accordance with the encoding *byte order* for the serialization and the encoding :attr:`byte_order` of the `Fiel...
f12145:c5:m22
def index_field(self, index=Index()):
<EOL>self.index = index<EOL>byte, bit, address, base, update = index<EOL>bit += self.bit_size<EOL>group_size, offset = divmod(bit, <NUM_LIT:8>)<EOL>if self.alignment.byte_size == group_size:<EOL><INDENT>if offset is not <NUM_LIT:0>:<EOL><INDENT>raise FieldGroupSizeError(self, index,<EOL>Alignment(group_size + <NUM_LIT:...
Indexes the `Field` with the given *index* und returns the :class:`Index` after the `Field`. :param Index index: start :class:`Index` for the `Field`.
f12145:c5:m23
@nested_option(True)<EOL><INDENT>def describe(self, name=str(), **options):<DEDENT>
metadata = {<EOL>'<STR_LIT:address>': self.index.address,<EOL>'<STR_LIT>': list(self.alignment),<EOL>'<STR_LIT:class>': self.name,<EOL>'<STR_LIT>': self.byte_order.value,<EOL>'<STR_LIT:index>': [self.index.byte, self.index.bit],<EOL>'<STR_LIT:name>': name if name else self.name,<EOL>'<STR_LIT:size>': self.bit_size,<EOL...
Returns the **metadata** of a `Field` as an :class:`ordered dictionary <collections.OrderedDict>`. .. code-block:: python metadata = { 'address': self.index.address, 'alignment': [self.alignment.byte_size, self.alignment.bit_offset], 'class':...
f12145:c5:m24
@property<EOL><INDENT>def name(self):<DEDENT>
size = len(self)<EOL>if size > <NUM_LIT:0>:<EOL><INDENT>return self.item_type.name.capitalize() + str(size)<EOL><DEDENT>else:<EOL><INDENT>return self.item_type.name.capitalize()<EOL><DEDENT>
Returns the type name of the `Stream` field (read-only).
f12145:c6:m6
@property<EOL><INDENT>def value(self):<DEDENT>
return hexlify(self._value).decode('<STR_LIT:ascii>')<EOL>
Field value as a lowercase hexadecimal encoded string.
f12145:c6:m7
def hex(self):
return hexlify(self._value).decode('<STR_LIT:ascii>')<EOL>
Returns a string containing two hexadecimal digits for each byte in the :attr:`value` of the `Stream` field.
f12145:c6:m9
@staticmethod<EOL><INDENT>def is_stream():<DEDENT>
return True<EOL>
Returns ``True``.
f12145:c6:m10
def resize(self, size):
count = max(int(size), <NUM_LIT:0>) - len(self)<EOL>if count == <NUM_LIT:0>:<EOL><INDENT>pass<EOL><DEDENT>elif -count == len(self):<EOL><INDENT>self._value = bytes()<EOL><DEDENT>elif count > <NUM_LIT:0>:<EOL><INDENT>self._value += b'<STR_LIT:\x00>' * count<EOL><DEDENT>else:<EOL><INDENT>self._value = self._value[:count]...
Re-sizes the `Stream` field by appending zero bytes or removing bytes from the end. :param int size: `Stream` size in number of bytes.
f12145:c6:m14
@property<EOL><INDENT>def value(self):<DEDENT>
length = self._value.find(b'<STR_LIT:\x00>')<EOL>if length >= <NUM_LIT:0>:<EOL><INDENT>return self._value[:length].decode('<STR_LIT:ascii>')<EOL><DEDENT>else:<EOL><INDENT>return self._value.decode('<STR_LIT:ascii>')<EOL><DEDENT>
Field value as an ascii encoded string.
f12145:c7:m0
@staticmethod<EOL><INDENT>def is_string():<DEDENT>
return True<EOL>
Returns ``True``.
f12145:c7:m2
def is_terminated(self):
return self._value.find(b'<STR_LIT:\x00>') >= <NUM_LIT:0><EOL>
Returns ``True`` if the `String` field is zero-terminated.
f12145:c7:m3
@property<EOL><INDENT>def value(self):<DEDENT>
return float(self._value)<EOL>
Field value as a single precision floating point number.
f12145:c8:m5
@staticmethod<EOL><INDENT>def is_float():<DEDENT>
return True<EOL>
Returns ``True``.
f12145:c8:m7
@staticmethod<EOL><INDENT>def smallest():<DEDENT>
return <NUM_LIT:2> ** -<NUM_LIT><EOL>
Returns the smallest possible field *value* of the `Float` field.
f12145:c8:m10
@staticmethod<EOL><INDENT>def max():<DEDENT>
return (<NUM_LIT:1> - Float.epsilon()) * <NUM_LIT:2> ** <NUM_LIT><EOL>
Returns the maximal possible field *value* of the `Float` field.
f12145:c8:m11
@staticmethod<EOL><INDENT>def min():<DEDENT>
return -(<NUM_LIT:1> - Float.epsilon()) * <NUM_LIT:2> ** <NUM_LIT><EOL>
Returns the minimal possible field *value* of the `Float` field.
f12145:c8:m12
@property<EOL><INDENT>def value(self):<DEDENT>
return int(self._value)<EOL>
Field value as a decimal number.
f12145:c9:m6
@property<EOL><INDENT>def signed(self):<DEDENT>
return self._signed<EOL>
Returns ``True`` if the `Decimal` field is signed.
f12145:c9:m8
@staticmethod<EOL><INDENT>def is_decimal():<DEDENT>
return True<EOL>
Returns ``True``.
f12145:c9:m10
def _set_alignment(self, group_size, bit_offset=<NUM_LIT:0>, auto_align=False):
<EOL>field_offset = int(bit_offset)<EOL>if auto_align:<EOL><INDENT>field_size, bit_offset = divmod(field_offset, <NUM_LIT:8>)<EOL>if bit_offset is not <NUM_LIT:0>:<EOL><INDENT>field_size += <NUM_LIT:1><EOL><DEDENT>field_size = max(field_size, <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>field_size = int(group_size)<EOL><...
Sets the alignment of the ``Decimal`` field. :param int group_size: size of the aligned `Field` group in bytes, can be between ``1`` and ``8``. :param int bit_offset: bit offset of the `Decimal` field within the aligned `Field` group, can be between ``0`` and ``63``. :pa...
f12145:c9:m12
def _set_bit_size(self, size, step=<NUM_LIT:1>, auto_align=False):
<EOL>bit_size = int(size)<EOL>if bit_size % step != <NUM_LIT:0> or not (<NUM_LIT:1> <= bit_size <= <NUM_LIT:64>):<EOL><INDENT>raise FieldSizeError(self, self.index, bit_size)<EOL><DEDENT>group_size, offset = divmod(bit_size, <NUM_LIT:8>)<EOL>if auto_align:<EOL><INDENT>if offset is not <NUM_LIT:0>:<EOL><INDENT>self._ali...
Sets the *size* of the `Decimal` field. :param int size: is the *size* of the `Decimal` field in bits, can be between ``1`` and ``64``. :param int step: is the minimal required step *size* for the `Decimal` field in bits. :param bool auto_align: if ``True`` the `Decimal`...
f12145:c9:m13
def max(self):
return self._max(self._signed)<EOL>
Returns the maximal possible field *value* of the `Decimal` field.
f12145:c9:m18
def min(self):
return self._min(self._signed)<EOL>
Returns the minimal possible field *value* of the `Decimal` field.
f12145:c9:m19
def as_unsigned(self):
return self._cast(self._value, self._min(False), self._max(False), False)<EOL>
Returns the field *value* of the `Decimal` field as an unsigned integer.
f12145:c9:m20
def as_signed(self):
return self._cast(self._value, self._min(True), self._max(True), True)<EOL>
Returns the field *value* of the `Decimal` field as a signed integer.
f12145:c9:m21
@property<EOL><INDENT>def name(self):<DEDENT>
return self.item_type.name.capitalize()<EOL>
Returns the type name of the `Bit` field (read-only).
f12145:c10:m1
@staticmethod<EOL><INDENT>def is_bit():<DEDENT>
return True<EOL>
Returns ``True``.
f12145:c10:m2
@property<EOL><INDENT>def name(self):<DEDENT>
return self.item_type.name.capitalize()<EOL>
Returns the type name of the `Byte` field (read-only).
f12145:c11:m1
@property<EOL><INDENT>def value(self):<DEDENT>
return hex(self._value)<EOL>
Field value as a lowercase hexadecimal string prefixed with ``0x``.
f12145:c11:m2
@property<EOL><INDENT>def name(self):<DEDENT>
return self.item_type.name.capitalize()<EOL>
Returns the type name of the `Char` field (read-only).
f12145:c12:m1
@property<EOL><INDENT>def value(self):<DEDENT>
return chr(self._value)<EOL>
Field value as an unicode string character.
f12145:c12:m2
@property<EOL><INDENT>def value(self):<DEDENT>
return hex(self._value)<EOL>
Field value as a lowercase hexadecimal string prefixed with ``0x``.
f12145:c14:m1
@property<EOL><INDENT>def value(self):<DEDENT>
return '<STR_LIT>'.format(self._value, self.bit_size + <NUM_LIT:2>)<EOL>
Field value as a binary string prefixed with ``0b``.
f12145:c15:m1
@property<EOL><INDENT>def value(self):<DEDENT>
return bool(self._value)<EOL>
Field value as a boolean value, ``True`` or ``False``.
f12145:c16:m1
@staticmethod<EOL><INDENT>def is_bool():<DEDENT>
return True<EOL>
Returns ``True``.
f12145:c16:m3
@property<EOL><INDENT>def value(self):<DEDENT>
if self._enum and issubclass(self._enum, Enumeration):<EOL><INDENT>name = self._enum.get_name(self._value)<EOL>if name:<EOL><INDENT>return name<EOL><DEDENT><DEDENT>return self._value<EOL>
Field value as an enum name string. Fall back is an unsigned integer number.
f12145:c17:m1
@property<EOL><INDENT>def value(self):<DEDENT>
return self.as_float(self._value)<EOL>
Field value as a floating point number.
f12145:c18:m2
@property<EOL><INDENT>def scale(self):<DEDENT>
return self._scale<EOL>
Scaling factor of the `Scaled` field.
f12145:c18:m6
def scaling_base(self):
return <NUM_LIT:2> ** (self.bit_size - <NUM_LIT:1>) / <NUM_LIT:2><EOL>
Returns the scaling base of the `Scaled` field.
f12145:c18:m8
@property<EOL><INDENT>def name(self):<DEDENT>
return "<STR_LIT>".format(self.item_type.name.capitalize(),<EOL>self._bits_integer,<EOL>self.bit_size)<EOL>
Returns the type name of the `Fraction` field (read-only).
f12145:c19:m2
@property<EOL><INDENT>def value(self):<DEDENT>
return self.as_float(self._value)<EOL>
Field value as a floating point number.
f12145:c19:m3
@property<EOL><INDENT>def value(self):<DEDENT>
return str(datetime.datetime.utcfromtimestamp(self._value))<EOL>
Field value as an UTC datetime string in the ISO format ``YYYY-mm-dd HH:MM:SS``
f12145:c22:m1
@property<EOL><INDENT>def value(self):<DEDENT>
return str(ipaddress.IPv4Address(self._value))<EOL>
Field value as an IPv4 address formatted string.
f12145:c23:m1
@property<EOL><INDENT>def address(self):<DEDENT>
return self._value<EOL>
Returns the *data source* address of the :attr:`data` object referenced by the `Pointer` field (read-only).
f12145:c24:m1
@property<EOL><INDENT>def base_address(self):<DEDENT>
return self._value<EOL>
Returns the *data source* base address of the :attr:`data` object referenced by the `Pointer` field (read-only).
f12145:c24:m2
@property<EOL><INDENT>def data(self):<DEDENT>
return self._data<EOL>
`Data` object referenced by the `Pointer` field.
f12145:c24:m5
@property<EOL><INDENT>def data_byte_order(self):<DEDENT>
return self._data_byte_order<EOL>
:class:`Byteorder` used to deserialize and serialize the :attr:`data` object referenced by the `Pointer` field.
f12145:c24:m7
@property<EOL><INDENT>def data_size(self):<DEDENT>
<EOL>if is_container(self._data):<EOL><INDENT>byte_length, bit_length = self._data.container_size()<EOL>return byte_length + math.ceil(bit_length / <NUM_LIT:8>)<EOL><DEDENT>elif is_field(self._data):<EOL><INDENT>return math.ceil(self._data.bit_size / <NUM_LIT:8>)<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT:0><EOL><DE...
Returns the size of the :attr:`data` object in bytes (read-only).
f12145:c24:m9
@property<EOL><INDENT>def value(self):<DEDENT>
return hex(self._value)<EOL>
Field value as a lowercase hexadecimal string prefixed with ``0x``.
f12145:c24:m10
@staticmethod<EOL><INDENT>def is_pointer():<DEDENT>
return True<EOL>
Returns ``True``.
f12145:c24:m12
def is_null(self):
return self._value is <NUM_LIT:0><EOL>
Returns ``True`` if the `Pointer` field points to zero.
f12145:c24:m13
def deserialize_data(self, buffer=bytes(), byte_order=None):
index = Index(<NUM_LIT:0>, <NUM_LIT:0>, self.address, self.base_address, False)<EOL>if self._data:<EOL><INDENT>if byte_order not in ('<STR_LIT>', '<STR_LIT>', Byteorder.little, Byteorder.big):<EOL><INDENT>byte_order = self.data_byte_order<EOL><DEDENT>index = self._data.deserialize(buffer or self._data_stream,<EOL>index...
De-serializes the :attr:`data` object referenced by the `Pointer` field from the byte *buffer* by mapping the bytes to the :attr:`~Field.value` for each :class:`Field` in the :attr:`data` object in accordance with the decoding *byte order* for the de-serialization and the decoding :attr:...
f12145:c24:m14
def serialize_data(self, byte_order=None):
if self._data is None:<EOL><INDENT>return bytes()<EOL><DEDENT>if byte_order not in ('<STR_LIT>', '<STR_LIT>', Byteorder.little, Byteorder.big):<EOL><INDENT>byte_order = self.data_byte_order<EOL><DEDENT>buffer = bytearray()<EOL>self._data.serialize(buffer,<EOL>Index(<NUM_LIT:0>, <NUM_LIT:0>,<EOL>self.address, self.base_...
Serializes the :attr:`data` object referenced by the `Pointer` field to bytes by mapping the :attr:`~Field.value` for each :class:`Field` in the :attr:`data` object to a number of bytes in accordance with the encoding *byte order* for the serialization and the encoding :attr:`byte_order`...
f12145:c24:m15
def index_data(self):
<EOL>index = Index(<NUM_LIT:0>, <NUM_LIT:0>, self.address, self.base_address, False)<EOL>if is_container(self._data):<EOL><INDENT>self._data.index_fields(index, nested=True)<EOL><DEDENT>elif is_pointer(self._data):<EOL><INDENT>self._data.index_field(index)<EOL>self._data.index_data()<EOL><DEDENT>elif is_field(self._dat...
Indexes each :class:`Field` in the :attr:`data` object referenced by the `Pointer` field.
f12145:c24:m16
@nested_option(True)<EOL><INDENT>def read_from(self, provider, null_allowed=False, **options):<DEDENT>
if self._data is None:<EOL><INDENT>pass<EOL><DEDENT>elif is_provider(provider):<EOL><INDENT>if self._value < <NUM_LIT:0>:<EOL><INDENT>pass<EOL><DEDENT>elif null_allowed or self._value > <NUM_LIT:0>:<EOL><INDENT>while True:<EOL><INDENT>self.bytestream = provider.read(self.address, self.data_size)<EOL>index = self.deseri...
Reads from the data :class:`Provider` the necessary number of bytes for the :attr:`data` object referenced by the `Pointer` field. A `Pointer` field stores the binary data read from the data :class:`Provider` in its :attr:`bytestream`. :param Provider provider: data :class:`Provider`. ...
f12145:c24:m17
def patch(self, item, byte_order=BYTEORDER):
<EOL>self.index_data()<EOL>if is_container(item):<EOL><INDENT>length = item.container_size()<EOL>if length[<NUM_LIT:1>] is not <NUM_LIT:0>:<EOL><INDENT>raise ContainerLengthError(item, length)<EOL><DEDENT>field = item.first_field()<EOL>if field is None:<EOL><INDENT>return None<EOL><DEDENT>index = field.index<EOL>if ind...
Returns a memory :class:`Patch` for the given *item* that shall be patched in the `data source`. :param item: item to patch. :param byte_order: encoding :class:`Byteorder` for the item. :type byte_order: :class:`Byteorder`, :class:`str`
f12145:c24:m18
def write_to(self, provider, item, byte_order=BYTEORDER):
<EOL>patch = self.patch(item, byte_order)<EOL>if patch is None:<EOL><INDENT>pass<EOL><DEDENT>elif is_provider(provider):<EOL><INDENT>if patch.inject:<EOL><INDENT>content = provider.read(patch.address, len(patch.buffer))<EOL>value = int.from_bytes(content, byte_order.value)<EOL>bit_mask = ~((<NUM_LIT:2> ** patch.bit_siz...
Writes via a data :class:`Provider` the :class:`Field` values of the given *item* to the `data source`. :param Provider provider: data :class:`Provider`. :param item: item to write. :param byte_order: encoding :class:`Byteorder`. :type byte_order: :class:`Byteorder`, :class:`str...
f12145:c24:m19
@byte_order_option()<EOL><INDENT>@nested_option()<EOL>def deserialize(self, buffer=bytes(), index=Index(), **options):<DEDENT>
<EOL>index = super().deserialize(buffer, index, **options)<EOL>if self._data and get_nested(options):<EOL><INDENT>options[Option.byte_order.value] = self.data_byte_order<EOL>self._data.deserialize(self._data_stream,<EOL>Index(<NUM_LIT:0>, <NUM_LIT:0>,<EOL>self.address, self.base_address,<EOL>False),<EOL>**options)<EOL>...
De-serializes the `Pointer` field from the byte *buffer* starting at the begin of the *buffer* or with the given *index* by mapping the bytes to the :attr:`value` of the `Pointer` field in accordance with the decoding *byte order* for the de-serialization and the decoding :attr:`byte_ord...
f12145:c24:m20
@byte_order_option()<EOL><INDENT>@nested_option()<EOL>def serialize(self, buffer=bytearray(), index=Index(), **options):<DEDENT>
<EOL>index = super().serialize(buffer, index, **options)<EOL>if self._data and get_nested(options):<EOL><INDENT>options[Option.byte_order.value] = self.data_byte_order<EOL>self._data_stream = bytearray()<EOL>self._data.serialize(self._data_stream,<EOL>Index(<NUM_LIT:0>, <NUM_LIT:0>,<EOL>self.address, self.base_address,...
Serializes the `Pointer` field to the byte *buffer* starting at the begin of the *buffer* or with the given *index* by mapping the :attr:`value` of the `Pointer` field to the byte *buffer* in accordance with the encoding *byte order* for the serialization and the encoding :attr:`byte_or...
f12145:c24:m21
def initialize_fields(self, content):
for name, value in content.items():<EOL><INDENT>if name is '<STR_LIT:value>':<EOL><INDENT>self.value = value<EOL><DEDENT>elif name is '<STR_LIT:data>':<EOL><INDENT>if is_mixin(self._data):<EOL><INDENT>self._data.initialize_fields(value)<EOL><DEDENT>elif is_field(self._data):<EOL><INDENT>self._data.value = value<EOL><DE...
Initializes the `Pointer` field itself and the :class:`Field` items in the :attr:`data` object referenced by the `Pointer` field with the *values* in the *content* dictionary. The ``['value']`` key in the *content* dictionary refers to the `Pointer` field itself and the ``['data']`` key...
f12145:c24:m22
@nested_option()<EOL><INDENT>def index_fields(self, index=Index(), **options):<DEDENT>
index = self.index_field(index)<EOL>if is_container(self._data):<EOL><INDENT>self._data.index_fields(Index(<NUM_LIT:0>, <NUM_LIT:0>,<EOL>self.address, self.base_address,<EOL>False),<EOL>**options)<EOL><DEDENT>elif is_pointer(self._data) and get_nested(options):<EOL><INDENT>self._data.index_fields(Index(<NUM_LIT:0>, <NU...
Indexes the `Pointer` field and the :attr:`data` object referenced by the `Pointer` field starting with the given *index* and returns the :class:`Index` after the `Pointer` field. :param Index index: :class:`Index` for the `Pointer` field. :keyword bool nested: if ``True`` all :class:`P...
f12145:c24:m23
@nested_option()<EOL><INDENT>def view_fields(self, *attributes, **options):<DEDENT>
items = OrderedDict()<EOL>if attributes:<EOL><INDENT>field_getter = attrgetter(*attributes)<EOL><DEDENT>else:<EOL><INDENT>field_getter = attrgetter('<STR_LIT:value>')<EOL><DEDENT>if len(attributes) > <NUM_LIT:1>:<EOL><INDENT>for key, value in zip(attributes, field_getter(self)):<EOL><INDENT>items[key] = value<EOL><DEDE...
Returns an :class:`ordered dictionary <collections.OrderedDict>` which contains the selected field *attributes* of the `Pointer` field itself extended with a ``['data']`` key which contains the selected field *attribute* or the dictionaries of the selected field *attributes* for each :class:`Fie...
f12145:c24:m24
@nested_option()<EOL><INDENT>def field_items(self, path=str(), **options):<DEDENT>
items = list()<EOL>items.append((path if path else '<STR_LIT>', self))<EOL>data_path = '<STR_LIT>'.format(path, '<STR_LIT:data>') if path else '<STR_LIT:data>'<EOL>if is_container(self._data):<EOL><INDENT>for field_item in self._data.field_items(data_path, **options):<EOL><INDENT>items.append(field_item)<EOL><DEDENT><D...
Returns a **flatten** list of ``('field path', field item)`` tuples for the `Pointer` field itself and for each :class:`Field` *nested* in the :attr:`data` object referenced by the `Pointer` field. :param str path: path of the `Pointer` field. :keyword bool nested: if ``True`` all :clas...
f12145:c24:m25
@nested_option(True)<EOL><INDENT>def describe(self, name=str(), **options):<DEDENT>
metadata = super().describe(name, **options)<EOL>metadata['<STR_LIT:class>'] = self.__class__.__name__<EOL>metadata['<STR_LIT:name>'] = name if name else self.__class__.__name__<EOL>metadata['<STR_LIT:type>'] = Pointer.item_type.name<EOL>if is_any(self._data) and get_nested(options):<EOL><INDENT>metadata['<STR_LIT>'] =...
Returns the **metadata** of a `Pointer` as an :class:`ordered dictionary <collections.OrderedDict>`. .. code-block:: python metadata = { 'address': self.index.address, 'alignment': [self.alignment.byte_size, self.alignment.bit_offset], 'class...
f12145:c24:m26
def append(self, item):
self._data.append(item)<EOL>
Appends the *item* to the end of the :class:`Sequence`. :param item: any :class:`Structure`, :class:`Sequence`, :class:`Array` or :class:`Field` instance.
f12145:c26:m6
def insert(self, index, item):
self._data.insert(index, item)<EOL>
Inserts the *item* before the *index* into the :class:`Sequence`. :param int index: :class:`Sequence` index. :param item: any :class:`Structure`, :class:`Sequence`, :class:`Array` or :class:`Field` instance.
f12145:c26:m7
def pop(self, index=-<NUM_LIT:1>):
return self._data.pop(index)<EOL>
Removes and returns the item at the *index* from the :class:`Sequence`. :param int index: :class:`Sequence` index.
f12145:c26:m8
def clear(self):
self._data.clear()<EOL>
Remove all items from the :class:`Sequence`.
f12145:c26:m9
def remove(self, item):
self._data.remove(item)<EOL>
Removes the first occurrence of an *item* from the :class:`Sequence`. :param item: any :class:`Structure`, :class:`Sequence`, :class:`Array` or :class:`Field` instance.
f12145:c26:m10