Documentation ¶
Overview ¶
genproc is a code generation tool for automatically creating pack/unpack routines which work with goat's built-in net.Protocol implementation. The application recursively searches a path for .go files and parses them, looking for structs which are marked up as network messages which also have fields marked for network export. For any relevant structs, a new type with the name <structName>Handler will be generated which implements the net.MsgProcessor interface. The new type and associated functions will be saved in a new file msg<structName>.go in the same directory as the source file which contained the marked up source struct.
Usage: genproc <search root directory> // Mark-up structs which you'll need to serialize/deserialize with a /* +NetMsg+ <message signature> */ tag /* +NetMsg+ 25 */ type ExampleNetMsg struct { Field1 int // +export+ Field2 string Field3 string // +export+ }
In this example, a new type ExampleNetMsgHandler will be created with relevant Close, Init, Deserialize, Serialize, and Signature functions. The Signature function will return the message signature contained in the +NetMsg+ comment tag (in this case 25, though it could also be a variable reference). The Serialize an Deserialize methods will pack and unpack Field1 and Field3 using the lib/buffer package. The user can then register ExNetMsgHandler with his/her chosen net.Protocol.