:py:mod:`dissect.cstruct.compiler` ================================== .. py:module:: dissect.cstruct.compiler Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: dissect.cstruct.compiler.Compiler .. py:class:: Compiler(cstruct: Compiler.__init__.cstruct) Compiler for cstruct structures. Creates somewhat optimized parsing code. .. py:attribute:: TYPES :value: () .. py:attribute:: COMPILE_TEMPLATE :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """ class {name}(Structure): def __init__(self, cstruct, structure, source=None): self.structure = structure self.source = source super().__init__(cstruct, structure.name, structure.fields, anonymous=structure.anonymous) def _read(self, stream, context=None): r = OrderedDict() sizes = {{}} bitreader = BitBuffer(stream, self.cstruct.endian) {read_code} return Instance(self, r, sizes) def add_field(self, name, type_, offset=None): raise NotImplementedError("Can't add fields to a compiled structure") def __repr__(self): return '' """ .. raw:: html
.. py:method:: compile(structure: dissect.cstruct.types.Structure) -> dissect.cstruct.types.Structure .. py:method:: gen_struct_class(name: str, structure: dissect.cstruct.types.Structure) -> str .. py:method:: gen_read_block(size: int, block: List[str]) -> str .. py:method:: gen_dynamic_block(field: dissect.cstruct.types.Field) -> str