segpy.packer module¶
-
class
segpy.packer.
BijectiveHeaderPacker
(header_format_class, structure, field_name_allocations)¶ Bases:
segpy.packer.HeaderPacker
One-to-one packing/unpacking of serialised values to header fields.
-
class
segpy.packer.
HeaderPacker
(header_format_class, structure, field_name_allocations)¶ Bases:
abc.ABC
Packing and unpacking header instances.
-
header_format_class
¶
-
pack
(header)¶ Pack a header into a buffer.
-
unpack
(buffer)¶ Unpack a header into a header object.
Overwrites any existing header field values with new values obtained from the buffer.
Returns: The header object.
-
-
class
segpy.packer.
SurjectiveHeaderPacker
(header_format_class, structure, field_name_allocations)¶ Bases:
segpy.packer.HeaderPacker
One-to-many unpacking of serialised values to header fields.
-
segpy.packer.
compile_struct
(header_format_class, start_offset=0, length_in_bytes=None, endian='>')¶ Compile a struct description from a record.
Parameters: - header_format_class – A header_format class.
- start_offset – Optional start offset for the header in bytes. Indicates the position of the start of the header in the same reference frame as which the field offsets are given.
- length_in_bytes – Optional length in bytes for the header. If the supplied header described a format shorter than this value the returned format will be padded with placeholders for bytes to be discarded. If the value is less than the minimum required for the format described by header_format_class an error will be raised.
- endian – ‘>’ for big-endian data (the standard and default), ‘<’ for little-endian (non-standard).
Returns: A two-tuple containing in the zeroth element a format string which can be used with the struct.unpack function, and in the second element containing a list-of-lists for field names. Each item in the outer list corresponds to an element of the tuple of data values returned by struct.unpack(); each name associated with that index is a field to which the unpacked value should be assigned.
Usage:
format, allocations = compile_struct(TraceHeaderFormat) values = struct.unpack(format) field_names_to_values = {} for field_names, value in zip(allocations, values): for field_name in field_names: field_names_to_values[field_name] = value header = Header(**field_names_to_values)
Raises: - ValueError - If header_format_class defines no fields.
- ValueError - If header_format_class contains fields which overlap but are not exactly coincident.
- ValueError - If header_format_class contains coincident fields of different types.
- ValueError - If header_format_class described a format longer than length_in_bytes.
-
segpy.packer.
make_header_packer
(header_format_class, endian='>')¶
-
segpy.packer.
size_of
(t)¶