Parser class

The main class for getting decoded frames from blackbox log files. It also builds the field definitions from the raw headers.

class orangebox.parser.Parser(reader: Reader)[source]

Parse and iterate over decoded frames.

Parameters:

reader (Reader) – The Reader used to iterate over the relevant bits of bytes

property headers: Dict[str, str | int | float | List[int | float]]

Headers key-value map. This will not contain the headers describing the field definitions. To get the raw headers see Reader instead. Key is a string, value can be a string, a number or a list of numbers.

Type:

dict

property events: List[Event]

Log events found during parsing. All the events are available only after parsing has finished.

Type:

List[Event]

property field_names: List[str]

A list of all field names found in the current header.

Type:

List[str]

property reader: Reader

Return the underlying Reader object.

Type:

Reader

Factory

To create a new instance use the static factory method:

# load the second session from a flash chip log
parser = Parser.load("btfl_all.bll", 2)
static Parser.load(path: str, log_index: int = 1) Parser[source]

Factory method to create a parser for a log file.

Parameters:
  • path – Path to blackbox log file

  • log_index – Index within log file (defaults to 1)

Return type:

Parser

Read data

# select the 3rd session
parser.set_log_index(3)

# print field values frame by frame
for i, frame in enumerate(parser.frames()):
    print("frame #{:d}: {!r}".format(i, frame))
Parser.frames() Iterator[Frame][source]

Return an iterator for the current frames.

Return type:

Iterator[Frame]

Parser.set_log_index(index: int)[source]

Select a log by index within the file. Calling this method will set the new index for the underlying Reader object and also update the header information as a side effect. The state of the parser will be reset.

The first index is 1. You can get the maximum number of logs from Reader.log_count.

See also Reader.set_log_index().

Parameters:

index – The selected log index