From 4450a20bde136c1ed462001073abe7253f8c934b Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 3 Feb 2018 00:24:48 -0500 Subject: [PATCH] types: check bufio.Reader --- types/messages.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/types/messages.go b/types/messages.go index be49461ad..2a7568d9f 100644 --- a/types/messages.go +++ b/types/messages.go @@ -28,7 +28,11 @@ func ReadMessage(r io.Reader, msg proto.Message) error { } func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) error { - reader := bufio.NewReader(r) + // binary.ReadVarint takes an io.ByteReader, eg. a bufio.Reader + reader, ok := r.(*bufio.Reader) + if !ok { + reader = bufio.NewReader(r) + } length64, err := binary.ReadVarint(reader) if err != nil { return err