Standard Library
Namespace: exbip
Parsers
Reader #
ReaderBase. Implements the standard library descriptors. A parser for deserializing bytes to Python objects. Designed for contiguous parsing.
Descriptor Method: deserialize
NonContiguousReader #
ReaderBase. Implements the standard library descriptors. A parser for deserializing bytes to Python objects. Designed for non-contiguous parsing.
Descriptor Method: deserialize
Validator #
ValidatorBase. Implements the standard library descriptors. A parser to verify whether two bytestreams deserialize to identical Python objects, and if not, to raise an error that originates at the first pair of read calls that deserialize to different values. Designed for contiguous parsing.
Descriptor Method: deserialize
Writer #
WriterBase. Implements the standard library descriptors. A parser for serializing Python objects to bytes. Designed for contiguous parsing.
Descriptor Method: serialize
Counter #
CounterBase. Implements the standard library descriptors. A parser for counting how many bytes a stream pointer will advance for each operator call. Designed for contiguous parsing.
Descriptor Method: count
OffsetCalculator #
OffsetCalculatorBase. Implements the standard library descriptors. A parser for counting how many bytes a stream pointer will advance for each operator call, and using this to calculate the value of stream-offset variables within a structure.
Descriptor Method: calculate_offsets if it exists. Else, count
Traits
ReadableTrait(Reader): #
filepath to the FileIO() method of Reader.
byte_data to the BytestreamIO() method of Reader.
WriteableTrait(Writer): #
filepath to the FileIO() method of Writer.
BytestreamIO() method of Writer.
ValidatableTrait(Validator): #
primary_filepath against the data in reference_filepath.
primary_filepath against the bytes in reference_bytes.
primary_bytes against the data in reference_filepath.
primary_bytes against the bytes in reference_bytes.
OffsetsCalculableTrait(OffsetCalculator): #
OffsetCalculator.rw_obj(obj, \*args, \*\*kwargs) on an instance of OffsetCalculator. This is intended to be used to automatically calculate the values of file offsets.
Operations
Primitives
rw_int8(value): #
value to 1 byte and writes it to the stream. Returns value.
value.
rw_int8_le(value)
Forced little-endian mode.
rw_int8_be(value)
Forced big-endian mode.
rw_int8_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_int16(value): #
value to 2 bytes and writes it to the stream. Returns value.
value.
rw_int16_le(value)
Forced little-endian mode.
rw_int16_be(value)
Forced big-endian mode.
rw_int16_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_int32(value): #
value to 4 bytes and writes it to the stream. Returns value.
value.
rw_int32_le(value)
Forced little-endian mode.
rw_int32_be(value)
Forced big-endian mode.
rw_int32_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_int64(value): #
value to 8 bytes and writes it to the stream. Returns value.
value.
rw_int64_le(value)
Forced little-endian mode.
rw_int64_be(value)
Forced big-endian mode.
rw_int64_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_uint8(value): #
value to 1 byte and writes it to the stream. Returns value.
value.
rw_uint8_le(value)
Forced little-endian mode.
rw_uint8_be(value)
Forced big-endian mode.
rw_uint8_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_uint16(value): #
value to 2 bytes and writes it to the stream. Returns value.
value.
rw_uint16_le(value)
Forced little-endian mode.
rw_uint16_be(value)
Forced big-endian mode.
rw_uint16_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_uint32(value): #
value to 4 bytes and writes it to the stream. Returns value.
value.
rw_uint32_le(value)
Forced little-endian mode.
rw_uint32_be(value)
Forced big-endian mode.
rw_uint32_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_uint64(value): #
value to 8 bytes and writes it to the stream. Returns value.
value.
rw_uint64_le(value)
Forced little-endian mode.
rw_uint64_be(value)
Forced big-endian mode.
rw_uint64_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_float16(value): #
value to 2 bytes and writes it to the stream. Returns value.
value.
rw_float16_le(value)
Forced little-endian mode.
rw_float16_be(value)
Forced big-endian mode.
rw_float16_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_float32(value): #
value to 4 bytes and writes it to the stream. Returns value.
value.
rw_float32_le(value)
Forced little-endian mode.
rw_float32_be(value)
Forced big-endian mode.
rw_float32_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_float64(value): #
value to 8 bytes and writes it to the stream. Returns value.
value.
rw_float64_le(value)
Forced little-endian mode.
rw_float64_be(value)
Forced big-endian mode.
rw_float64_e(value, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
Primitive Arrays
rw_int8s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_int8s_le(value, shape)
Forced little-endian mode.
rw_int8s_be(value, shape)
Forced big-endian mode.
rw_int8s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_int16s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_int16s_le(value, shape)
Forced little-endian mode.
rw_int16s_be(value, shape)
Forced big-endian mode.
rw_int16s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_int32s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_int32s_le(value, shape)
Forced little-endian mode.
rw_int32s_be(value, shape)
Forced big-endian mode.
rw_int32s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_int64s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_int64s_le(value, shape)
Forced little-endian mode.
rw_int64s_be(value, shape)
Forced big-endian mode.
rw_int64s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_uint8s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_uint8s_le(value, shape)
Forced little-endian mode.
rw_uint8s_be(value, shape)
Forced big-endian mode.
rw_uint8s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_uint16s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_uint16s_le(value, shape)
Forced little-endian mode.
rw_uint16s_be(value, shape)
Forced big-endian mode.
rw_uint16s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_uint32s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_uint32s_le(value, shape)
Forced little-endian mode.
rw_uint32s_be(value, shape)
Forced big-endian mode.
rw_uint32s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_uint64s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_uint64s_le(value, shape)
Forced little-endian mode.
rw_uint64s_be(value, shape)
Forced big-endian mode.
rw_uint64s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_float16s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_float16s_le(value, shape)
Forced little-endian mode.
rw_float16s_be(value, shape)
Forced big-endian mode.
rw_float16s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_float32s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_float32s_le(value, shape)
Forced little-endian mode.
rw_float32s_be(value, shape)
Forced big-endian mode.
rw_float32s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
rw_float64s(value, shape): #
shape.
value in row-major order and writes it to the stream. Returns value.
value. Returns value.
rw_float64s_le(value, shape)
Forced little-endian mode.
rw_float64s_be(value, shape)
Forced big-endian mode.
rw_float64s_e(value, shape, endianness)
Runtime endianness. Pass '<' or '>' for little- or big-endianness respectively.
Strings
rw_bytestring(value, length): #
length chars from the stream. Returns a bytes object.
value to the stream. Expects value to be a bytes-like object. Returns value.
value. Expects value to be a bytes object. Returns value.
rw_bytestrings(value, lengths): #
length chars from the stream. Returns a List[bytes] object.
value to the stream. Expects value to be an iterable of bytes-like objects. Returns value.
value. Expects value to be an iterable of bytes-like objects. Returns value.
rw_cbytestring(value[, chunksize=0x40, terminator=b'\x00']): #
chunksize until the terminator pattern is identified in one of those blocks. Returns a bytes object without the terminator.
value to the stream, and then writes the terminator. Expects value to be a bytes-like object. Returns value.
value plus the length of the terminator. Expects value to be an iterable of bytes-like objects. Returns value.
rw_cbytestrings(value, count[, chunksize=0x40, terminator=b'\x00']): #
chunksize until the terminator pattern is identified in one of those blocks, count times. Returns a List[bytes] object.
terminator) in value to the stream. Expects value to be an iterable of bytes-like objects. Returns value.
value (plus the requisite terminator lengths). Expects value to be an iterable of bytes-like objects. Returns value.
Descriptors
rw_descriptor(descriptor, *args, **kwargs): #
Objects
rw_obj(value, *args, **kwargs): #
exbip_rw function on value.
exbip_rw on value.
exbip_rw on value.
exbip_rw on value.
rw_dynamic_obj(value, constructor, *args, **kwargs): #
exbip_rw function on value if not deserializing, otherwise constructs it first.
constructor to build a new object, then calls exbip_rw on it.
exbip_rw on value.
exbip_rw on value.
rw_dynamic_objs(values, constructor, count, *args, **kwargs): #
exbip_rw function on value if not deserializing, otherwise constructs to object array first from a count.
constructor to build a new object, then calls exbip_rw on it, count times.
exbip_rw on each element in values.
exbip_rw on each element in values.
rw_dynamic_objs_while(values, constructor, condition, *args, **kwargs): #
exbip_rw function on value if not deserializing, otherwise constructs to object array first from a boolean condition.
constructor to build a new object, then calls exbip_rw on it, until calling condition returns False. condition must be a function (or functor) that takes the parser as its only argument.
exbip_rw on each element in values.
exbip_rw on each element in values.
Iterators
array_iterator(array, constructor, count): #
count array elements if deserializing, and iterate through an array if not. Example:
for i, obj in enumerate(rw.array_iterator(arr, MyObject, my_count)):
rw.check_stream_offset(obj_offsets[i], "Object {i}", HEX32_FORMATTER)
rw.rw_obj(obj)
rw_dynamic_objs.
array.
array.
array_while_iterator(array, constructor, stop_condition): #
condition is False if deserializing, and iterate through an array if not. Example:
class Cond:
def __init__(self, offset):
self.offset = offset
def __call__(self, rw):
return rw.tell() < self.offset
offset_list = []
for obj in rw.array_while_iterator(arr, MyObject, Cond(offset)):
offset_list.append(rw.tell())
rw.rw_obj(obj)
rw_dynamic_objs_while.
array.
array.
Sections
section_exists(offset, count): #
offset is greater than 0.
count is greater than 0.
count is greater than 0.
Stream End-of-file
assert_eof(): #
NotAtEOFError if the stream pointer is not at the end of the stream.
Stream Alignment
align(offset, alignment(, pad_value=b'\x00'): #
offset to the next multiple of alignment, and performs an operation on the section of the stream corresponding to the skipped bytes.
pad_values. Raises ValueError if the number of bytes required for the alignment is not divisible by the length of pad_value.
pad_values to the stream to perform the alignment. Raises ValueError if the number of bytes required for the alignment is not divisible by the length of pad_value.
alignment. Raises ValueError if the number of bytes required for the alignment is not divisible by the length of pad_value.
fill(offset, alignment(, fill_value=b'\x00'): #
offset to the next multiple of alignment, and performs an operation on the section of the stream corresponding to the skipped bytes.
pad_values to the stream to perform the alignment. Raises ValueError if the number of bytes required for the alignment is not divisible by the length of pad_value.
alignment. Raises ValueError if the number of bytes required for the alignment is not divisible by the length of pad_value.
Stream Offsets
verify_stream_offset(offset, message[, formatter=lambda x: x, notifier=None]): #
offset, throws an error if the stream offset is not at offset, or calls notifier with the current stream offset.
offset.
UnexpectedOffsetError if the stream offset is not at offset.
notifier.notify() if notifier is not None. Commonly, notifier is an OffsetMarker object.
navigate_stream_offset(offset, message[, formatter=lambda x: x, notifier=None]): #
offset, throws an error if the stream offset is not at offset, or calls notifier with the current stream offset.
offset.
notifier.notify() if notifier is not None. Commonly, notifier is an OffsetMarker object.
verify_stream_offset(offset, message[, formatter=lambda x: x, notifier=None]): #
offset, or calls notifier with the current stream offset.
UnexpectedOffsetError if the stream offset is not at offset.
UnexpectedOffsetError if the stream offset is not at offset.
notifier.notify() if notifier is not None. Commonly, notifier is an OffsetMarker object.
check_stream_offset(offset, message[, formatter=lambda x: x, notifier=None]): #
verify_stream_offset. Used by all standard parsers except NonContiguousReader.
check_stream_offset(offset, message[, formatter=lambda x: x, notifier=None]): #
enforce_stream_offset. Used by NonContiguousReader.
Stream Padding
rw_padding(count[, pad_value=b'\x00', validate=True]): #
count.
count*len(pad_value) bytes from the stream. If validate is True, the bytes are checked to ensure they are an array of pad_value. If they are not, an UnexpectedPaddingError is raised.
count pad_values to the stream.
count*len(pad_value).
Offset Markers
dispatch_marker(marker): #
notify method, expected to be an OffsetMarker object.
marker.notify().
Formatters
safe_formatter(formatter): #
safe_formatter object that calls formatter, which is a format method like e.g. '0b{0:0>8b}'.format, and returns the call return value if it does not throw an exception. On throwing a ValueError or TypeError, the original value is returned. Other exceptions are uncaught.
bin8_formatter(value): #
safe_formatter that formats value as an 8-bit binary string.
bin16_formatter(value): #
safe_formatter that formats value as a 16-bit binary string.
bin32_formatter(value): #
safe_formatter that formats value as a 32-bit binary string.
bin64_formatter(value): #
safe_formatter that formats value as a 64-bit binary string.
hex8_formatter(value): #
safe_formatter that formats value as an 8-bit lower-case hex string.
hex16_formatter(value): #
safe_formatter that formats value as a 16-bit lower-case hex string.
hex32_formatter(value): #
safe_formatter that formats value as a 32-bit lower-case hex string.
hex64_formatter(value): #
safe_formatter that formats value as a 64-bit lower-case hex string.
HEX8_formatter(value): #
safe_formatter that formats value as an 8-bit upper-case hex string.
HEX16_formatter(value): #
safe_formatter that formats value as a 16-bit upper-case hex string.
HEX32_formatter(value): #
safe_formatter that formats value as a 32-bit upper-case hex string.
HEX64_formatter(value): #
safe_formatter that formats value as a 64-bit upper-case hex string.
Structures
OffsetMarker #
notify is called, the offset passed to notify is used to call each of these callbacks, each of which is intended to give a particular variable the value of that offset.
lambda offset: setattr(obj, attr, offset) to the OffsetMarker's callbacks list. Returns self so that multiple subscriptions can be chained with the constructor.
callback to the OffsetMarker's callbacks list. Returns self so that multiple subscriptions can be chained with the constructor.
offset.