github.com/as/wire9 (go): Package wire9 provides a boilerplate protocol generator.  Wire9 parses wire definitions from a go package or source file.  It generates structs and methods according to the given definition.  To use wire9, run the standalone command line program on a go package directory containing wire definitions.  Wire Definitions:  A wire definition begins with a slash comment and wire9 prefix. There is no space between the slashes and prefix. The prefix is followed by a struct name and a variadic list of fields.  A field becomes the name of a struct field. Next, a [bracket-enclosed], comma-seperated list of field options: width, type, and endian.  Width is a field's binary width. Its value is an integer constant, a previously-defined numeric field, or empty.  Types specify a field's type.  This affects the type value in the final struct field, numeric and fixed types may have empty widths.  Endian specifies byte-order (LE or BE), which stand for Little-Endian and Big-Endian. Little-Endian is the default value.  The width and type are interpreted one of three ways depending on other values in the field options:  Width is a numeric literal A. Type is empty: If width is 1, 2, 4, or 8, type is byte, uint16, uint32, and uint64, respectively. Otherwise type is []byte.  B. Type is identifier: The type represents a fixed width struct, numeric value, or slice type. The width must match the fixed types binary width or be the number of expected slice elements.  Width is identifier A. Type is empty: Type is implicitly []byte. The width represents the number of bytes to expect in the slice.  B. Type is identifier: The type represents a slice type. The width is the number of expected elements in the slice.  Width is empty A. Type is a fixed-width struct, number, or implements the Wire interface.  Examples:  //wire9 Ex1A Time[8]        IP[4]        Port[2]         n[1] //wire9 Ex1B Time[8,uint64] IP[4,uint32] Port[2,uint16]  n[1,byte]  //wire9 Ex2A n[1]  URL[n] //wire9 Ex2B n[1]  URL[n,[]byte]  //wire9 Ex3A p[,image.Point]  size[,int64]  reply[,Ex2A]  //wire9 Git index[4,,BE] ...  Example:  The wire definition for a two-byte length-prefixed string:  Generates the following struct and (fully-implemented) methods:  This example defines four common length-prefixed strings  The following construction builds on the last example.  The value of the four 4-byte integers set the expected number of slice elements for each corresponding length-prefixed string.  Trivia:  The goal of this package is to save time when implementing custom protocols, such as Microsoft RDP. The package's original purpose was to take the Plan 9 draw(3) manual page and generate Go for parsing the messages written to the data file.
Keywords: generator|go|protocol