Construct struct wrappers¶
Custom construct fields and utilities
-
class
xbox.sg.utils.struct.XStruct(*args, **kwargs)¶ Bases:
construct.core.Subconstruct-
parse(data, **contextkw)¶ Parse an in-memory buffer (often bytes object). Strings, buffers, memoryviews, and other complete buffers can be parsed with this method.
Whenever data cannot be read, ConstructError or its derivative is raised. This method is NOT ALLOWED to raise any other exceptions although (1) user-defined lambdas can raise arbitrary exceptions which are propagated (2) external libraries like numpy can raise arbitrary exceptions which are propagated (3) some list and dict lookups can raise IndexError and KeyError which are propagated.
Context entries are passed only as keyword parameters **contextkw.
- Parameters
**contextkw – context entries, usually empty
- Returns
some value, usually based on bytes read from the stream but sometimes it is computed from nothing or from the context dictionary, sometimes its non-deterministic
- Raises
ConstructError – raised for any reason
-
-
class
xbox.sg.utils.struct.XStructObj(struct, container=None)¶ Bases:
construct.core.Subconstruct-
property
container¶
-
build(**contextkw)¶ Build an object in memory (a bytes object).
Whenever data cannot be written, ConstructError or its derivative is raised. This method is NOT ALLOWED to raise any other exceptions although (1) user-defined lambdas can raise arbitrary exceptions which are propagated (2) external libraries like numpy can raise arbitrary exceptions which are propagated (3) some list and dict lookups can raise IndexError and KeyError which are propagated.
Context entries are passed only as keyword parameters **contextkw.
- Parameters
**contextkw – context entries, usually empty
- Returns
bytes
- Raises
ConstructError – raised for any reason
-
property
-
xbox.sg.utils.struct.flatten(container)¶ Flattens StructWrap objects into just Container’s.
Recursively walks down each value of the Container, flattening possible StructWrap objects.
- Parameters
container (Container) – The container to flatten.
- Returns
A flattened container.
- Return type
Container