protobuf: Support encoding/decoding from any stream

When encoding to a stream we prefix the message with a varint
listing its length.  When decoding we read that varint, then use an
input stream wrapper which limits the number of bytes we consume
to that length.  This way the stream is left unaffected for the
next data segment, which might be something else.

Callers can use these to implement java.io.Serializable using their
own ProtobufCodec rather than relying on Java serialization.

Change-Id: I17fc5863b525fad22d14653831024eaf5b4ff9da
Signed-off-by: Shawn O. Pearce <sop@google.com>
3 files changed