akrennmair/gopcap — pull request #9 by gconnell (2011-11-27 07:14:30+00:00)
Title: Make packet headers a specific interface.

This is a slightly more involved change than the first few I've sent. It changes a packet's Headers from interface{} to a new Header interface. Currently, this interface just as a HeaderType() (enumerated in decode.go) and a Bytes() slice, which returns the bytes detected to be part of the header.

This allows for a couple of nice things. First, it makes switching based on header type easy (switch pkt.HeaderType() {}). Also, it opens up the ability to do cursory parsing of certain header types without fully coding them. If, for example, there's a header X that doesn't affect the ending payload, we can decode and skip it without fully coding the decode() function. I'm planning to do this next with IPv6 extensions, basically a quick initial implementation that does nothing but pulls out Bytes() and HeaderType(), and leaves the rest of the decoding for a later time.