This page will explain how to encode a parser.
Currently katydid supports several encoders:
- reflected go structures
This assumes you have already constructed a parser, if not see the page on parser usage.
Using an Encoder
Encoding json and xml is quite easy.
Encoding a reflect go structure requires the structure into which will be encoded, or rather unmarshaled.
Finally encoding into a protocol buffer (marshaling/dynamic transcoding) is a little bit more involved.
Dynamic encoding means that the protocol buffer does not necessarily need to be compiled in the program. Parsing the .proto files with protoc can give you a fileDescriptorSet which specifies the protocol buffer message. The packageName and messageName are used to locate the message in the fileDescriptorSet. The fileDescriptorSet can also be generated by gogoprotobuf as a method on the message.
The encoder can be reused and providing a large enough buffer to encode means that the buffer can also be reused.