summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-11-22 11:05:54 -0800
committerHarrison Healey <harrisonmhealey@gmail.com>2016-11-22 14:05:54 -0500
commit7961599b2e41c71720a42b3bfde641f7529f05fe (patch)
tree3c039e1d3790a954ba65fe551c7b348331bce994 /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go
parente033dcce8e57ed6b6684227adf9b29347e4718b3 (diff)
downloadchat-7961599b2e41c71720a42b3bfde641f7529f05fe.tar.gz
chat-7961599b2e41c71720a42b3bfde641f7529f05fe.tar.bz2
chat-7961599b2e41c71720a42b3bfde641f7529f05fe.zip
PLT-4357 adding performance monitoring (#4622)
* WIP * WIP * Adding metrics collection * updating vendor packages * Adding metrics to config * Adding admin console page for perf monitoring * Updating glide * switching to tylerb/graceful
Diffstat (limited to 'vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go')
-rw-r--r--vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go
new file mode 100644
index 000000000..8fb59ad22
--- /dev/null
+++ b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go
@@ -0,0 +1,46 @@
+// Copyright 2013 Matt T. Proud
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package pbutil
+
+import (
+ "encoding/binary"
+ "io"
+
+ "github.com/golang/protobuf/proto"
+)
+
+// WriteDelimited encodes and dumps a message to the provided writer prefixed
+// with a 32-bit varint indicating the length of the encoded message, producing
+// a length-delimited record stream, which can be used to chain together
+// encoded messages of the same type together in a file. It returns the total
+// number of bytes written and any applicable error. This is roughly
+// equivalent to the companion Java API's MessageLite#writeDelimitedTo.
+func WriteDelimited(w io.Writer, m proto.Message) (n int, err error) {
+ buffer, err := proto.Marshal(m)
+ if err != nil {
+ return 0, err
+ }
+
+ var buf [binary.MaxVarintLen32]byte
+ encodedLength := binary.PutUvarint(buf[:], uint64(len(buffer)))
+
+ sync, err := w.Write(buf[:encodedLength])
+ if err != nil {
+ return sync, err
+ }
+
+ n, err = w.Write(buffer)
+ return n + sync, err
+}