Converter module#
Sub-package for conversion from bytes to Frame.
- class galaxy_beep_frame.converter.Lexer(graph: Graph = <factory>, frame: Node[Token] | None = None, header: Node[Token] | None = None, size: int = 0, continuation_indicator: int | None = None, end: bytearray = <factory>, current_token: Token | None = None, state: State = State.START)#
Lexer convert a bytes into tokens graph.
Notes#
The graph structure is a hierarchical structure in the graph:
root (id: root) + frame (has frame)
header (has header) - message type (has message type) - channel number (has channel number) - message number (has message number) - continuation indicator (has continuation indicator) - sequence number (has sequence number) . answer number (has answer number)
payload
where: - + : many - - : exactly one - . : one or zero
Frame can be fetched from the graph. They are considered as completed when in a immutable state.
- static connections_to_human(connections: set[Connection], indent: int = 1) str#
Convert a list of connections to readable str rep.
- lex(reader: Reader[__annotationlib_name_1__], chunk_size: int = 100) list[Node[Token]]#
Lex on stream of bytes.
Warnings#
This will keep every frames in memory!
- lex_byte(char: int) Node[Token] | None#
Read a byte with current context.
This function update context in function of the value of this byte.
- lex_iterator(reader: Reader[__annotationlib_name_1__], chunk_size: int = 100) Iterator[__annotationlib_name_2__]#
Lex stream of bytes, yield frame node as they complete.
- async lex_stream(reader: StreamReader, chunk_size: int = 100) list[Node[Token]]#
Lex on async stream of bytes.
Warnings#
This will keep every frames in memory!
- async lex_stream_iterator(reader: StreamReader, chunk_size: int = 100) AsyncIterator[__annotationlib_name_1__]#
Lex async stream of bytes, yield node as they complete.
- class galaxy_beep_frame.converter.MutabilityState(token: Token)#
Information concerning mutability state.
- is_mutable() bool#
Inform about the mutability of the state.
- class galaxy_beep_frame.converter.MutableState(token: Token)#
Mutable state.
- end() None#
Switch mutability of the token.
- is_mutable() Literal[True]#
Return the mutability of the state.
- update(char: int) None#
Update value stored in the token by appending a byte.
- class galaxy_beep_frame.converter.Parser#
Convert a graph of token generated by lexer and validate it.
- class galaxy_beep_frame.converter.State(*values)#
Possible Lexer state.
- class galaxy_beep_frame.converter.Token(type: TokenType, value: bytearray = <factory>)#
Hold information about current state and value.
Start mutable (eg. can be modified) and can become irreversably immutable.
- class galaxy_beep_frame.converter.TokenType(*values)#
Possible token tyes.