pyfebiopt.xplt.binary_reader

Utility for reading FEBio PLT tags via a memory-mapped file.

Classes

BinaryReader

TLV reader optimized for FEBio .xplt.

Module Contents

class pyfebiopt.xplt.binary_reader.BinaryReader(filename: str)

TLV reader optimized for FEBio .xplt.

Design

  • Memory-mapped file, zero-copy slices.

  • Iterative tag scan (no recursion).

  • Integer cursor pos replaces file seeks.

  • Backward compatible API: read, search_block, check_block, seek_block.

Notes:

Tag records are stored as little-endian:

[u32 tag][u32 size][size bytes of payload]

Memory-map the xplt file for fast tag scanning.

__slots__ = ('_buf', '_f', '_mm', '_tag2int', 'filesize', 'pos')
filesize
pos = 0
__repr__() str
__str__
tell() int

Return the current cursor position.

seek(offset: int, whence: int = os.SEEK_SET) None

Move the cursor according to the requested offset.

skip(n: int) None

Advance the cursor by the requested number of bytes.

read(n: int = 4) bytes

Return n bytes and advance.

read_u32() int

Read little-endian unsigned 32-bit.

Returns:

Parsed value.

Return type:

int

peek_u32() int

Peek next u32 without advancing.

Returns:

Next 32-bit value without moving the cursor.

Return type:

int

read_f32() float

Read a little-endian float32 from the buffer.

Returns:

Parsed value.

Return type:

float

search_block(BLOCK_TAG: str, _max_depth: int = 5, _cur_depth: int = 0, _print_tag: int = 0, print_tag: int | None = None) int

Scan forward for the next tag. Return payload size or -1.

Leaves cursor at the payload start of the found block. Restores position if not found.

Returns:

Payload size in bytes, or -1 when not found.

Return type:

int

check_block(BLOCK_TAG: str, filesize: int = -1) int

Return 1 if next header’s tag equals BLOCK_TAG. Cursor unchanged.

seek_block(BLOCK_TAG: str) int

Consume the next header if it matches. Return payload size.

Cursor is left at the payload start.

Returns:

Payload size in bytes.

Return type:

int

close() None

Release resources held by the reader.

__del__() None

Attempt a clean shutdown when the reader is garbage collected.