One programming that perpetually bothers me is network protocol parsing. While not to hard to handle one or two special cases, a general approach is much more difficult. To confuse the mater, you quickly run into issues like message serialization and handling asynchronous communication.
Initially I had tried representing protocols as a nested structure (like Russian dolls), which works for representing simple packet structures, but falls apart when confronted with situations like HTTP where one HTTP message might be represented by one or more TCP packets (fragmentation) or maybe sharing a TCP packet with other HTTP messages (packing), as well as having the issue of having no where to store protocol state.
Currently the best way I'm seen of doing protocol parsing is to think of it as a stack of protocol layers where the lower layers refine information before parsing it higher layers. This is the approach that Twisted takes where by a Protocol consumes bytes via the `dataReceived(bytes)` method until enough data has been received to pass the data to one or my higher level layers.
If you've seen better ways of thinking about network protocols, I'd love to hear about it.
Initially I had tried representing protocols as a nested structure (like Russian dolls), which works for representing simple packet structures, but falls apart when confronted with situations like HTTP where one HTTP message might be represented by one or more TCP packets (fragmentation) or maybe sharing a TCP packet with other HTTP messages (packing), as well as having the issue of having no where to store protocol state.
Currently the best way I'm seen of doing protocol parsing is to think of it as a stack of protocol layers where the lower layers refine information before parsing it higher layers. This is the approach that Twisted takes where by a Protocol consumes bytes via the `dataReceived(bytes)` method until enough data has been received to pass the data to one or my higher level layers.
If you've seen better ways of thinking about network protocols, I'd love to hear about it.