pbutil - ActiveState ActiveGo 1.8
...

Package pbutil

import "github.com/matttproud/golang_protobuf_extensions/pbutil"
Overview
Index

Overview ▾

Package pbutil provides record length-delimited Protocol Buffer streaming.

func ReadDelimited

func ReadDelimited(r io.Reader, m proto.Message) (n int, err error)

ReadDelimited decodes a message from the provided length-delimited stream, where the length is encoded as 32-bit varint prefix to the message body. It returns the total number of bytes read and any applicable error. This is roughly equivalent to the companion Java API's MessageLite#parseDelimitedFrom. As per the reader contract, this function calls r.Read repeatedly as required until exactly one message including its prefix is read and decoded (or an error has occurred). The function never reads more bytes from the stream than required. The function never returns an error if a message has been read and decoded correctly, even if the end of the stream has been reached in doing so. In that case, any subsequent calls return (0, io.EOF).

func WriteDelimited

func WriteDelimited(w io.Writer, m proto.Message) (n int, err error)

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.