benbjohnson/go-raft — pull request #77 by benbjohnson (2013-07-17 16:03:16+00:00)
Title: [Fix #74] Refactor to use binary log and binary RPCs.

@xiangli-cmu This PR looks huge but it's mainly just converting JSON encodings to binary encodings. Nothing too fancy. Also, the HTTP transport uses `application/octet-stream`.

The `Command` types will use a JSON encoding by default unless there are `Encode()` and `Decode()` functions on them. That way you can override to write straight to the `Reader`/`Writer`.

Here's the new benchmarks:

```
$ go test -test.bench=.
PASS
BenchmarkAppendEntriesRequestEncoding	2000	1391891 ns/op	96.31 MB/s
BenchmarkAppendEntriesRequestDecoding	1000	1818073 ns/op	73.73 MB/s
BenchmarkAppendEntriesResponseEncoding	10000000	247 ns/op	117.12 MB/s
BenchmarkAppendEntriesResponseDecoding	10000000	208 ns/op	139.05 MB/s
```

Also, thanks to @peterbourgon. I used his binary encoding as a starting point. I made some tweaks to account for `io.ErrUnexpectedEOF` and for internal protocol versioning.