Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions wire/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ type uint64Time time.Time
// The callback is called with a short buffer of 8 bytes in length, and only
// size bytes should be read from this array.
//
// For longer reads and reads of byte arrays, dynamic dispatch to r.Read
// should be used instead.
// For longer reads and reads of byte arrays, io.ReadFull should be used
// instead.
//
// This function will panic if called with a size greater than 8.
func shortRead(r io.Reader, size int, cb func(p [8]byte)) error {
Expand Down Expand Up @@ -163,19 +163,10 @@ func shortRead(r io.Reader, size int, cb func(p [8]byte)) error {

default:
p := binarySerializer.Borrow()
n, err := r.Read(p[:size])
if err == io.EOF && n > 0 {
return io.ErrUnexpectedEOF
}
_, err := io.ReadFull(r, p[:size])
if err != nil {
return err
}
if n == 0 {
return io.EOF
}
if n != size {
return io.ErrUnexpectedEOF
}
cb(*(*[8]byte)(p))
binarySerializer.Return(p)
}
Expand Down