Implement simulator #873
Labels
architectural decision
Discussion of design decision
simulator
Related to simulator package (Python API)
topic
Large feature/change
Background
Goals:
Replace PyRFLX
From a RecordFlux specification
Pythonic / natural implementation
Related Work - Message Parsing / Generation
https://github.com/Componolit/rflx_simulator_experiments
Examples
(tests/data/specs/tlv.rflx)
Test Data - Msg_Data
Test Data - Msg_Error
Test Data - Invalid Tag
Construct
https://github.com/construct/construct
Specification
This is probably wrong - it does not really make "length" and "value" optional as I would have expected. The project does have significant documentation, but it often does not cover the more complicated cases.
Parsing
Generation
Hachoir
https://github.com/vstinner/hachoir
Specification
Parsing
Generation
Not supported (there is an editor module to change parsed data, though).
Kaitai Struct
https://kaitai.io/
Specification
The specification is translated to Python code using the Kaitai struct compiler (ksc):
$ ksc --target python tlv.ksy
The resulting tlv.py file contains the parser. A support library (kaitaistruct) is required for it to work.
Parsing
Generation
Not supported
Python Suitcase
https://github.com/digidotcom/python-suitcase
Specification
Parsing
Generation
Scapy
https://scapy.net/
Specification
Parsing
Generation
Message Parser Design
Option 1.1
Pro: Natural interface
Con: Static typing may be impossible / hard
Option 1.2
Pro: Short, easier / more natural to be used programmatically
Con: Generation is asymmetric, no reuse of same model with different data
Option 1.3
Pro: Symmetric interface possible, reuse of previously parsed message
Con: Stateful
Option 1.4
Pro: easier / more natural to be used programmatically
Con: Static typing may be impossible / hard
Option 1.5
Pro: Place where checksum functions (and later parameters) are passed is consistent with specification, package hierarchy in the spec is mirrored by the code
Con: Checksum needs to passed whenever message is constructed
Option 1.6
Alternative version with inline specification:
Pro: Can be statically type-checked by mypy, central place for checksum functions, different child classes associated with different specs
Con: Name mangling of checksum function may become confusing, more code
Conclusion
Implement 1.5(mypy does not provide hooks necessary to check this version)Implement 1.6
Data Getter Design
Option 2.1
Pro: Better readability, natural to use
Con: translation from RecordFlux names to Python necessary to avoid style check issues
Option 2.2
Pro: Field names identical to spec, iteration over fields could be implemented on top
Con: Verbose
Option 2.3
Pro: Field names identical to spec
Con: Verbose
Conclusion
Implement 2.1
Data Setter Design
Option 3.1
Pro: Better readability, natural to use
Con: translation from RecordFlux names to Python necessary to avoid style check issues
Option 3.2
Pro: Field names identical to spec, iteration over fields could be implemented on top
Con: Verbose, calls need to be in right order
Option 3.3
Pro: Field names identical to spec
Con: Verbose, calls need to be in right order
Option 3.4
Pro: Field names identical to spec, great flexibility
Con: Partial update may not be possible
Option 3.5message = { "Tag": value }Assignment cannot be overloaded in Python
Conclusion
Implement 3.1
Message Serializer Design
Option 4.1
Pro: Natural interface
Con:
Option 4.2
Pro: Natural interface, very pythonic
Con:
Conclusion
4.2
Checksum Design
Option 5.1
Pro: Natural interface
Con: Must be set per message, not suitable for parsing
Option 5.2
Pro: Checksum only set per simulator instance
Con: TLV.Message addressed in two distinct places / ways
Option 5.3
Cf. 1.5
Conclusion
5.3
Enumeration Literals Design
Option 6.1
Pro: Compatible with int
Con: Error prone, user needs to perform mapping from enum to integer manually
Option 6.2
Pro: Compatible with int (when based on IntEnum)
Con:
Conclusion
6.2
Summary - Message Parser
Related Work - State Machines
Pysmlib
https://darcato.github.io/pysmlib/docs/html/index.html
FiniteStateMachines
https://github.com/jaypantone/FiniteStateMachines
PythonStateMachine
https://python-statemachine.readthedocs.io/en/latest/index.html
Transitions
https://github.com/pytransitions/transitions
PySM
https://pysm.readthedocs.io/en/latest/#
StateEngine
https://github.com/aymanimtyaz/StateEngine
The text was updated successfully, but these errors were encountered: