diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-04-16 05:37:14 -0700 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-04-16 08:37:14 -0400 |
commit | 6e2cb00008cbf09e556b00f87603797fcaa47e09 (patch) | |
tree | 3c0eb55ff4226a3f024aad373140d1fb860a6404 /vendor/github.com/go-redis/redis/internal/proto/reader.go | |
parent | bf24f51c4e1cc6286885460672f7f449e8c6f5ef (diff) | |
download | chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.gz chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.bz2 chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.zip |
Depenancy upgrades and movign to dep. (#8630)
Diffstat (limited to 'vendor/github.com/go-redis/redis/internal/proto/reader.go')
-rw-r--r-- | vendor/github.com/go-redis/redis/internal/proto/reader.go | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/vendor/github.com/go-redis/redis/internal/proto/reader.go b/vendor/github.com/go-redis/redis/internal/proto/reader.go index e5ae8a03e..d5d695358 100644 --- a/vendor/github.com/go-redis/redis/internal/proto/reader.go +++ b/vendor/github.com/go-redis/redis/internal/proto/reader.go @@ -6,7 +6,7 @@ import ( "io" "strconv" - "github.com/go-redis/redis/internal" + "github.com/go-redis/redis/internal/util" ) const bytesAllocLimit = 1024 * 1024 // 1mb @@ -19,6 +19,16 @@ const ( ArrayReply = '*' ) +//------------------------------------------------------------------------------ + +const Nil = RedisError("redis: nil") + +type RedisError string + +func (e RedisError) Error() string { return string(e) } + +//------------------------------------------------------------------------------ + type MultiBulkParse func(*Reader, int64) (interface{}, error) type Reader struct { @@ -66,7 +76,7 @@ func (r *Reader) ReadLine() ([]byte, error) { return nil, fmt.Errorf("redis: reply is empty") } if isNilReply(line) { - return nil, internal.Nil + return nil, Nil } return line, nil } @@ -83,7 +93,7 @@ func (r *Reader) ReadReply(m MultiBulkParse) (interface{}, error) { case StatusReply: return parseStatusValue(line), nil case IntReply: - return parseInt(line[1:], 10, 64) + return util.ParseInt(line[1:], 10, 64) case StringReply: return r.readTmpBytesValue(line) case ArrayReply: @@ -105,7 +115,7 @@ func (r *Reader) ReadIntReply() (int64, error) { case ErrorReply: return 0, ParseErrorReply(line) case IntReply: - return parseInt(line[1:], 10, 64) + return util.ParseInt(line[1:], 10, 64) default: return 0, fmt.Errorf("redis: can't parse int reply: %.100q", line) } @@ -151,7 +161,7 @@ func (r *Reader) ReadFloatReply() (float64, error) { if err != nil { return 0, err } - return parseFloat(b, 64) + return util.ParseFloat(b, 64) } func (r *Reader) ReadArrayReply(m MultiBulkParse) (interface{}, error) { @@ -221,7 +231,7 @@ func (r *Reader) ReadScanReply() ([]string, uint64, error) { func (r *Reader) readTmpBytesValue(line []byte) ([]byte, error) { if isNilReply(line) { - return nil, internal.Nil + return nil, Nil } replyLen, err := strconv.Atoi(string(line[1:])) @@ -241,7 +251,7 @@ func (r *Reader) ReadInt() (int64, error) { if err != nil { return 0, err } - return parseInt(b, 10, 64) + return util.ParseInt(b, 10, 64) } func (r *Reader) ReadUint() (uint64, error) { @@ -249,7 +259,7 @@ func (r *Reader) ReadUint() (uint64, error) { if err != nil { return 0, err } - return parseUint(b, 10, 64) + return util.ParseUint(b, 10, 64) } // -------------------------------------------------------------------- @@ -303,7 +313,7 @@ func isNilReply(b []byte) bool { } func ParseErrorReply(line []byte) error { - return internal.RedisError(string(line[1:])) + return RedisError(string(line[1:])) } func parseStatusValue(line []byte) []byte { @@ -312,23 +322,7 @@ func parseStatusValue(line []byte) []byte { func parseArrayLen(line []byte) (int64, error) { if isNilReply(line) { - return 0, internal.Nil + return 0, Nil } - return parseInt(line[1:], 10, 64) -} - -func atoi(b []byte) (int, error) { - return strconv.Atoi(internal.BytesToString(b)) -} - -func parseInt(b []byte, base int, bitSize int) (int64, error) { - return strconv.ParseInt(internal.BytesToString(b), base, bitSize) -} - -func parseUint(b []byte, base int, bitSize int) (uint64, error) { - return strconv.ParseUint(internal.BytesToString(b), base, bitSize) -} - -func parseFloat(b []byte, bitSize int) (float64, error) { - return strconv.ParseFloat(internal.BytesToString(b), bitSize) + return util.ParseInt(line[1:], 10, 64) } |