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 | |
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')
7 files changed, 77 insertions, 263 deletions
diff --git a/vendor/github.com/go-redis/redis/internal/proto/proto_test.go b/vendor/github.com/go-redis/redis/internal/proto/proto_test.go deleted file mode 100644 index c9a820eb1..000000000 --- a/vendor/github.com/go-redis/redis/internal/proto/proto_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package proto_test - -import ( - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -func TestGinkgoSuite(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "proto") -} 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) } diff --git a/vendor/github.com/go-redis/redis/internal/proto/reader_test.go b/vendor/github.com/go-redis/redis/internal/proto/reader_test.go deleted file mode 100644 index 8d2d71be9..000000000 --- a/vendor/github.com/go-redis/redis/internal/proto/reader_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package proto_test - -import ( - "bytes" - "strings" - "testing" - - "github.com/go-redis/redis/internal/proto" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("Reader", func() { - - It("should read n bytes", func() { - data, err := proto.NewReader(strings.NewReader("ABCDEFGHIJKLMNO")).ReadN(10) - Expect(err).NotTo(HaveOccurred()) - Expect(len(data)).To(Equal(10)) - Expect(string(data)).To(Equal("ABCDEFGHIJ")) - - data, err = proto.NewReader(strings.NewReader(strings.Repeat("x", 8192))).ReadN(6000) - Expect(err).NotTo(HaveOccurred()) - Expect(len(data)).To(Equal(6000)) - }) - - It("should read lines", func() { - p := proto.NewReader(strings.NewReader("$5\r\nhello\r\n")) - - data, err := p.ReadLine() - Expect(err).NotTo(HaveOccurred()) - Expect(string(data)).To(Equal("$5")) - - data, err = p.ReadLine() - Expect(err).NotTo(HaveOccurred()) - Expect(string(data)).To(Equal("hello")) - }) - -}) - -func BenchmarkReader_ParseReply_Status(b *testing.B) { - benchmarkParseReply(b, "+OK\r\n", nil, false) -} - -func BenchmarkReader_ParseReply_Int(b *testing.B) { - benchmarkParseReply(b, ":1\r\n", nil, false) -} - -func BenchmarkReader_ParseReply_Error(b *testing.B) { - benchmarkParseReply(b, "-Error message\r\n", nil, true) -} - -func BenchmarkReader_ParseReply_String(b *testing.B) { - benchmarkParseReply(b, "$5\r\nhello\r\n", nil, false) -} - -func BenchmarkReader_ParseReply_Slice(b *testing.B) { - benchmarkParseReply(b, "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", multiBulkParse, false) -} - -func benchmarkParseReply(b *testing.B, reply string, m proto.MultiBulkParse, wanterr bool) { - buf := new(bytes.Buffer) - for i := 0; i < b.N; i++ { - buf.WriteString(reply) - } - p := proto.NewReader(buf) - b.ResetTimer() - - for i := 0; i < b.N; i++ { - _, err := p.ReadReply(m) - if !wanterr && err != nil { - b.Fatal(err) - } - } -} - -func multiBulkParse(p *proto.Reader, n int64) (interface{}, error) { - vv := make([]interface{}, 0, n) - for i := int64(0); i < n; i++ { - v, err := p.ReadReply(multiBulkParse) - if err != nil { - return nil, err - } - vv = append(vv, v) - } - return vv, nil -} diff --git a/vendor/github.com/go-redis/redis/internal/proto/scan.go b/vendor/github.com/go-redis/redis/internal/proto/scan.go index 0329ffd99..3bdb33f9d 100644 --- a/vendor/github.com/go-redis/redis/internal/proto/scan.go +++ b/vendor/github.com/go-redis/redis/internal/proto/scan.go @@ -5,7 +5,7 @@ import ( "fmt" "reflect" - "github.com/go-redis/redis/internal" + "github.com/go-redis/redis/internal/util" ) func Scan(b []byte, v interface{}) error { @@ -13,80 +13,80 @@ func Scan(b []byte, v interface{}) error { case nil: return fmt.Errorf("redis: Scan(nil)") case *string: - *v = internal.BytesToString(b) + *v = util.BytesToString(b) return nil case *[]byte: *v = b return nil case *int: var err error - *v, err = atoi(b) + *v, err = util.Atoi(b) return err case *int8: - n, err := parseInt(b, 10, 8) + n, err := util.ParseInt(b, 10, 8) if err != nil { return err } *v = int8(n) return nil case *int16: - n, err := parseInt(b, 10, 16) + n, err := util.ParseInt(b, 10, 16) if err != nil { return err } *v = int16(n) return nil case *int32: - n, err := parseInt(b, 10, 32) + n, err := util.ParseInt(b, 10, 32) if err != nil { return err } *v = int32(n) return nil case *int64: - n, err := parseInt(b, 10, 64) + n, err := util.ParseInt(b, 10, 64) if err != nil { return err } *v = n return nil case *uint: - n, err := parseUint(b, 10, 64) + n, err := util.ParseUint(b, 10, 64) if err != nil { return err } *v = uint(n) return nil case *uint8: - n, err := parseUint(b, 10, 8) + n, err := util.ParseUint(b, 10, 8) if err != nil { return err } *v = uint8(n) return nil case *uint16: - n, err := parseUint(b, 10, 16) + n, err := util.ParseUint(b, 10, 16) if err != nil { return err } *v = uint16(n) return nil case *uint32: - n, err := parseUint(b, 10, 32) + n, err := util.ParseUint(b, 10, 32) if err != nil { return err } *v = uint32(n) return nil case *uint64: - n, err := parseUint(b, 10, 64) + n, err := util.ParseUint(b, 10, 64) if err != nil { return err } *v = n return nil case *float32: - n, err := parseFloat(b, 32) + n, err := util.ParseFloat(b, 32) if err != nil { return err } @@ -94,7 +94,7 @@ func Scan(b []byte, v interface{}) error { return err case *float64: var err error - *v, err = parseFloat(b, 64) + *v, err = util.ParseFloat(b, 64) return err case *bool: *v = len(b) == 1 && b[0] == '1' @@ -120,7 +120,7 @@ func ScanSlice(data []string, slice interface{}) error { return fmt.Errorf("redis: ScanSlice(non-slice %T)", slice) } - next := internal.MakeSliceNextElemFunc(v) + next := makeSliceNextElemFunc(v) for i, s := range data { elem := next() if err := Scan([]byte(s), elem.Addr().Interface()); err != nil { @@ -131,3 +131,36 @@ func ScanSlice(data []string, slice interface{}) error { return nil } + +func makeSliceNextElemFunc(v reflect.Value) func() reflect.Value { + elemType := v.Type().Elem() + + if elemType.Kind() == reflect.Ptr { + elemType = elemType.Elem() + return func() reflect.Value { + if v.Len() < v.Cap() { + v.Set(v.Slice(0, v.Len()+1)) + elem := v.Index(v.Len() - 1) + if elem.IsNil() { + elem.Set(reflect.New(elemType)) + } + return elem.Elem() + } + + elem := reflect.New(elemType) + v.Set(reflect.Append(v, elem)) + return elem.Elem() + } + } + + zero := reflect.Zero(elemType) + return func() reflect.Value { + if v.Len() < v.Cap() { + v.Set(v.Slice(0, v.Len()+1)) + return v.Index(v.Len() - 1) + } + + v.Set(reflect.Append(v, zero)) + return v.Index(v.Len() - 1) + } +} diff --git a/vendor/github.com/go-redis/redis/internal/proto/scan_test.go b/vendor/github.com/go-redis/redis/internal/proto/scan_test.go deleted file mode 100644 index fadcd0561..000000000 --- a/vendor/github.com/go-redis/redis/internal/proto/scan_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package proto - -import ( - "encoding/json" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -type testScanSliceStruct struct { - ID int - Name string -} - -func (s *testScanSliceStruct) MarshalBinary() ([]byte, error) { - return json.Marshal(s) -} - -func (s *testScanSliceStruct) UnmarshalBinary(b []byte) error { - return json.Unmarshal(b, s) -} - -var _ = Describe("ScanSlice", func() { - data := []string{ - `{"ID":-1,"Name":"Back Yu"}`, - `{"ID":1,"Name":"szyhf"}`, - } - - It("[]testScanSliceStruct", func() { - var slice []testScanSliceStruct - err := ScanSlice(data, &slice) - Expect(err).NotTo(HaveOccurred()) - Expect(slice).To(Equal([]testScanSliceStruct{ - {-1, "Back Yu"}, - {1, "szyhf"}, - })) - }) - - It("var testContainer []*testScanSliceStruct", func() { - var slice []*testScanSliceStruct - err := ScanSlice(data, &slice) - Expect(err).NotTo(HaveOccurred()) - Expect(slice).To(Equal([]*testScanSliceStruct{ - {-1, "Back Yu"}, - {1, "szyhf"}, - })) - }) -}) diff --git a/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go b/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go index 096b6d76a..cc4014fb4 100644 --- a/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go +++ b/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go @@ -71,17 +71,15 @@ func (w *WriteBuffer) append(val interface{}) error { } else { w.AppendString("0") } - default: - if bm, ok := val.(encoding.BinaryMarshaler); ok { - bb, err := bm.MarshalBinary() - if err != nil { - return err - } - w.AppendBytes(bb) - } else { - return fmt.Errorf( - "redis: can't marshal %T (consider implementing encoding.BinaryMarshaler)", val) + case encoding.BinaryMarshaler: + b, err := v.MarshalBinary() + if err != nil { + return err } + w.AppendBytes(b) + default: + return fmt.Errorf( + "redis: can't marshal %T (consider implementing encoding.BinaryMarshaler)", val) } return nil } diff --git a/vendor/github.com/go-redis/redis/internal/proto/write_buffer_test.go b/vendor/github.com/go-redis/redis/internal/proto/write_buffer_test.go deleted file mode 100644 index 84799ff3b..000000000 --- a/vendor/github.com/go-redis/redis/internal/proto/write_buffer_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package proto_test - -import ( - "testing" - "time" - - "github.com/go-redis/redis/internal/proto" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("WriteBuffer", func() { - var buf *proto.WriteBuffer - - BeforeEach(func() { - buf = proto.NewWriteBuffer() - }) - - It("should reset", func() { - buf.AppendString("string") - Expect(buf.Len()).To(Equal(12)) - buf.Reset() - Expect(buf.Len()).To(Equal(0)) - }) - - It("should append args", func() { - err := buf.Append([]interface{}{ - "string", - 12, - 34.56, - []byte{'b', 'y', 't', 'e', 's'}, - true, - nil, - }) - Expect(err).NotTo(HaveOccurred()) - Expect(buf.Bytes()).To(Equal([]byte("*6\r\n" + - "$6\r\nstring\r\n" + - "$2\r\n12\r\n" + - "$5\r\n34.56\r\n" + - "$5\r\nbytes\r\n" + - "$1\r\n1\r\n" + - "$0\r\n" + - "\r\n"))) - }) - - It("should append marshalable args", func() { - err := buf.Append([]interface{}{time.Unix(1414141414, 0)}) - Expect(err).NotTo(HaveOccurred()) - Expect(buf.Len()).To(Equal(26)) - }) - -}) - -func BenchmarkWriteBuffer_Append(b *testing.B) { - buf := proto.NewWriteBuffer() - args := []interface{}{"hello", "world", "foo", "bar"} - - for i := 0; i < b.N; i++ { - buf.Append(args) - buf.Reset() - } -} |