forked from mirror/redis
Cleanup readLine
This commit is contained in:
parent
b66d05bd63
commit
e1b0a0bd7e
|
@ -69,29 +69,27 @@ func (r *Reader) ReadLine() ([]byte, error) {
|
|||
// - there is a pending read error;
|
||||
// - or line does not end with \r\n.
|
||||
func (r *Reader) readLine() ([]byte, error) {
|
||||
var s []byte
|
||||
multi := false
|
||||
for {
|
||||
b, err := r.rd.ReadSlice('\n')
|
||||
if err != nil {
|
||||
// in case the end of the buffer is not reached
|
||||
if err == bufio.ErrBufferFull {
|
||||
s = append(s, b...)
|
||||
multi = true
|
||||
continue
|
||||
} else {
|
||||
if err != bufio.ErrBufferFull {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
full := make([]byte, len(b))
|
||||
copy(full, b)
|
||||
|
||||
b, err = r.rd.ReadBytes('\n')
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
full = append(full, b...)
|
||||
b = full
|
||||
}
|
||||
if len(b) <= 2 || b[len(b)-1] != '\n' || b[len(b)-2] != '\r' {
|
||||
return nil, fmt.Errorf("redis: invalid reply: %q", b)
|
||||
}
|
||||
if multi {
|
||||
b = append(s, b...)
|
||||
}
|
||||
b = b[:len(b)-2]
|
||||
return b, nil
|
||||
}
|
||||
return b[:len(b)-2], nil
|
||||
}
|
||||
|
||||
func (r *Reader) ReadReply(m MultiBulkParse) (interface{}, error) {
|
||||
|
|
Loading…
Reference in New Issue