Parsing bencode format data with a FSM (now with pictures!)
Sep 10th, 2010 by Adam
Many of my recent posts have been about my Finite State Machine engine, and what it can (and does) do. As one of the examples provided with the engine, I provide a parser for bencode format, the data formatting style used in torrent files, torrent trackers, etc. It makes a great example as its easy to understand, from a novice perspective, and it parses well (heck, its isometric!).
As part of the FSM examples, I am generating visualizations for the included FSMs via dot, a utility part of the GraphViz collection. It’s a great tool for generating digraphs. I just finished the visualizations for bencode format, so I thought I would share! As always, if you have a question, leave a comment or send me an email: adam@adamrisi.com.
Entry points are always node “0″, and the example’s entry point is the bencode_fsm node 0. Pretty neat, eh? It’s a perfect translation of the bencode standard into a working FSM.




