sourcegraph / appdash

Application tracing system for Go, based on Google's Dapper.
https://sourcegraph.com
Other
1.72k stars 137 forks source link

Switch to protobuf #32

Closed slimsag closed 9 years ago

slimsag commented 9 years ago

This PR switches the form of communication from the previously-used JSON, to Google's protobuf.

A new package has the .proto file and protobuf-generated Go source files: internal/wire. This is the same proto file other languages can make use of to communicate.

Protobuf itself only handles the marshaling and unmarshaling of messages: it does not have any built-in capability to handle streams of messages (i.e. what we need). According to the docs, it is up to applications to implement this themselves. We make use of a binary-compatable protobuf fork with a sub-package io which provides a delimited message writer for streams of data. Essentially, it just writes a protobuf varint into the stream describing how big the next message is. This should be pretty trivial to adapt to other languages, and the source code for that package is very straight-forward.

For those reviewing this change, the rational for removing bufio usage -- and the rational for not closing the conn anymore -- is that gogo/protobuf/io uses bufio internally and closes the underlying io.WriteCloser when you close a writer. No need to duplicate work.

go generate can be used to regenerate the Go protobuf code in the new internal/wire package easily.

Helps issue #31