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