What is the Pythonic way to implement a simple FSM?

后端 未结 7 1628
猫巷女王i
猫巷女王i 2021-01-31 21:50

Yesterday I had to parse a very simple binary data file - the rule is, look for two bytes in a row that are both 0xAA, then the next byte will be a length byte, then skip 9 byte

7条回答
  •  醉梦人生
    2021-01-31 22:29

    I think the most pythonic way would by like what FogleBird suggested, but mapping from (current state, input) to a function which would handle the processing and transition.

提交回复
热议问题