commit | 23af6d7d9736e2906a08f94da7e9de9f23b96b9e | [log] [tgz] |
---|---|---|
author | Matt T. Proud <matt.proud@gmail.com> | Sun Apr 20 19:01:40 2014 |
committer | Matt T. Proud <matt.proud@gmail.com> | Thu Apr 24 22:21:31 2014 |
tree | 5d26b468b305638e8dccf15db128a65a3fc1d5dc | |
parent | f251fd0a51789b1424fde01a078fe53b26af295d [diff] |
Support for buffer retention and include example. This commit introduces ``DelimitedBuffer`` type, which functions as a reusable buffer for message encoding and decoding. A strong critique of the old implementation is that it carelessly allocated ephemeral buffers, so this is a means of alleviating problems around that.
This repository provides various Protocol Buffer extensions for the Go language (golang), namely support for record length-delimited message streaming.
$ go get github.com/matttproud/golang_protobuf_extensions/ext
package main import ( "io" "code.google.com/p/goprotobuf/proto" "github.com/matttproud/golang_protobuf_extensions/ext" ) func main() { // You have your pre-populated Protocol Buffer messages. Yay! msgs := []proto.Message{firstMsg, secondMsg, thirdMsg} // Destination for writing. buf := new(ext.DelimitedBuffer) for _, m := range msgs { buf.Marshal(m) // Write each out. m.Reset() // Clear the message, since we'll read it back in. } for _, m := range msgs { _, err := buf.Unmarshal(m) // Read each in ... if err == io.EOF { // until we hit EOF or break } else if err != nil { // encounter an error. panic(err) } } }
We have generated Go Doc documentation here.