Browse Source

types: check bufio.Reader

pull/1780/head
Ethan Buchman 7 years ago
parent
commit
4450a20bde
1 changed files with 5 additions and 1 deletions
  1. +5
    -1
      types/messages.go

+ 5
- 1
types/messages.go View File

@ -28,7 +28,11 @@ func ReadMessage(r io.Reader, msg proto.Message) error {
} }
func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) 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) length64, err := binary.ReadVarint(reader)
if err != nil { if err != nil {
return err return err


Loading…
Cancel
Save