diff --git a/NOTICE.txt b/NOTICE.txt index ecd5f5e15a6..4609e0f8e44 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -6839,40 +6839,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------- -Dependency: gopkg.in/vmihailenco/msgpack.v2 -Revision: f4f8982de4ef0de18be76456617cc3f5d8d8141e -License type (autodetected): BSD-3-Clause -./vendor/gopkg.in/vmihailenco/msgpack.v2/LICENSE: --------------------------------------------------------------------- -Copyright (c) 2013 The msgpack for Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -------------------------------------------------------------------- Dependency: gopkg.in/yaml.v2 Revision: 5420a8b6744d3b0345ab293f6fcba19c978f1183 diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/LICENSE b/vendor/gopkg.in/vmihailenco/msgpack.v2/LICENSE deleted file mode 100644 index bafc76b689c..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2013 The msgpack for Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/Makefile b/vendor/gopkg.in/vmihailenco/msgpack.v2/Makefile deleted file mode 100644 index b62ae6a46e3..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: - go test ./... - env GOOS=linux GOARCH=386 go test ./... - go test ./... -short -race - go vet diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/README.md b/vendor/gopkg.in/vmihailenco/msgpack.v2/README.md deleted file mode 100644 index 12985b29d06..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# MessagePack encoding for Golang - -[![Build Status](https://travis-ci.org/vmihailenco/msgpack.svg?branch=v2)](https://travis-ci.org/vmihailenco/msgpack) -[![GoDoc](https://godoc.org/github.com/vmihailenco/msgpack?status.svg)](https://godoc.org/github.com/vmihailenco/msgpack) - -Supports: -- Primitives, arrays, maps, structs, time.Time and interface{}. -- Appengine *datastore.Key and datastore.Cursor. -- [CustomEncoder](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#example-CustomEncoder)/CustomDecoder interfaces for custom encoding. -- [Extensions](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#example-RegisterExt) to encode type information. -- Renaming fields via `msgpack:"my_field_name"`. -- Inlining struct fields via `msgpack:",inline"`. -- Omitting empty fields via `msgpack:",omitempty"`. -- [Map keys sorting](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#Encoder.SortMapKeys). -- Encoding/decoding all [structs as arrays](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#Encoder.StructAsArray) or [individual structs](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#example-Marshal--AsArray). -- Simple but very fast and efficient [queries](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#example-Decoder-Query). - -API docs: https://godoc.org/gopkg.in/vmihailenco/msgpack.v2. -Examples: https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#pkg-examples. - -## Installation - -Install: - -```shell -go get gopkg.in/vmihailenco/msgpack.v2 -``` - -## Quickstart - -```go -func ExampleMarshal() { - type Item struct { - Foo string - } - - b, err := msgpack.Marshal(&Item{Foo: "bar"}) - if err != nil { - panic(err) - } - - var item Item - err = msgpack.Unmarshal(b, &item) - if err != nil { - panic(err) - } - fmt.Println(item.Foo) - // Output: bar -} -``` - -## Benchmark - -``` -BenchmarkStructVmihailencoMsgpack-4 200000 12814 ns/op 2128 B/op 26 allocs/op -BenchmarkStructUgorjiGoMsgpack-4 100000 17678 ns/op 3616 B/op 70 allocs/op -BenchmarkStructUgorjiGoCodec-4 100000 19053 ns/op 7346 B/op 23 allocs/op -BenchmarkStructJSON-4 20000 69438 ns/op 7864 B/op 26 allocs/op -BenchmarkStructGOB-4 10000 104331 ns/op 14664 B/op 278 allocs/op -``` - -## Howto - -Please go through [examples](https://godoc.org/gopkg.in/vmihailenco/msgpack.v2#pkg-examples) to get an idea how to use this package. - -## See also - -- [Golang PostgreSQL ORM](https://github.com/go-pg/pg) -- [Golang message task queue](https://github.com/go-msgqueue/msgqueue) diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/appengine.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/appengine.go deleted file mode 100644 index 43614247fc5..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/appengine.go +++ /dev/null @@ -1,69 +0,0 @@ -// +build appengine - -package msgpack - -import ( - "reflect" - - ds "google.golang.org/appengine/datastore" -) - -var ( - keyPtrType = reflect.TypeOf((*ds.Key)(nil)) - cursorType = reflect.TypeOf((*ds.Cursor)(nil)).Elem() -) - -func init() { - Register(keyPtrType, encodeDatastoreKeyValue, decodeDatastoreKeyValue) - Register(cursorType, encodeDatastoreCursorValue, decodeDatastoreCursorValue) -} - -func EncodeDatastoreKey(e *Encoder, key *ds.Key) error { - if key == nil { - return e.EncodeNil() - } - return e.EncodeString(key.Encode()) -} - -func encodeDatastoreKeyValue(e *Encoder, v reflect.Value) error { - key := v.Interface().(*ds.Key) - return EncodeDatastoreKey(e, key) -} - -func DecodeDatastoreKey(d *Decoder) (*ds.Key, error) { - v, err := d.DecodeString() - if err != nil { - return nil, err - } - if v == "" { - return nil, nil - } - return ds.DecodeKey(v) -} - -func decodeDatastoreKeyValue(d *Decoder, v reflect.Value) error { - key, err := DecodeDatastoreKey(d) - if err != nil { - return err - } - v.Set(reflect.ValueOf(key)) - return nil -} - -func encodeDatastoreCursorValue(e *Encoder, v reflect.Value) error { - cursor := v.Interface().(ds.Cursor) - return e.Encode(cursor.String()) -} - -func decodeDatastoreCursorValue(d *Decoder, v reflect.Value) error { - s, err := d.DecodeString() - if err != nil { - return err - } - cursor, err := ds.DecodeCursor(s) - if err != nil { - return err - } - v.Set(reflect.ValueOf(cursor)) - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/codes/codes.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/codes/codes.go deleted file mode 100644 index b2b12074ee0..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/codes/codes.go +++ /dev/null @@ -1,76 +0,0 @@ -package codes - -var ( - PosFixedNumHigh byte = 0x7f - NegFixedNumLow byte = 0xe0 - - Nil byte = 0xc0 - - False byte = 0xc2 - True byte = 0xc3 - - Float byte = 0xca - Double byte = 0xcb - - Uint8 byte = 0xcc - Uint16 byte = 0xcd - Uint32 byte = 0xce - Uint64 byte = 0xcf - - Int8 byte = 0xd0 - Int16 byte = 0xd1 - Int32 byte = 0xd2 - Int64 byte = 0xd3 - - FixedStrLow byte = 0xa0 - FixedStrHigh byte = 0xbf - FixedStrMask byte = 0x1f - Str8 byte = 0xd9 - Str16 byte = 0xda - Str32 byte = 0xdb - - Bin8 byte = 0xc4 - Bin16 byte = 0xc5 - Bin32 byte = 0xc6 - - FixedArrayLow byte = 0x90 - FixedArrayHigh byte = 0x9f - FixedArrayMask byte = 0xf - Array16 byte = 0xdc - Array32 byte = 0xdd - - FixedMapLow byte = 0x80 - FixedMapHigh byte = 0x8f - FixedMapMask byte = 0xf - Map16 byte = 0xde - Map32 byte = 0xdf - - FixExt1 byte = 0xd4 - FixExt2 byte = 0xd5 - FixExt4 byte = 0xd6 - FixExt8 byte = 0xd7 - FixExt16 byte = 0xd8 - Ext8 byte = 0xc7 - Ext16 byte = 0xc8 - Ext32 byte = 0xc9 -) - -func IsFixedNum(c byte) bool { - return c <= PosFixedNumHigh || c >= NegFixedNumLow -} - -func IsFixedMap(c byte) bool { - return c >= FixedMapLow && c <= FixedMapHigh -} - -func IsFixedArray(c byte) bool { - return c >= FixedArrayLow && c <= FixedArrayHigh -} - -func IsFixedString(c byte) bool { - return c >= FixedStrLow && c <= FixedStrHigh -} - -func IsExt(c byte) bool { - return (c >= FixExt1 && c <= FixExt16) || (c >= Ext8 && c <= Ext32) -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/decode.go deleted file mode 100644 index 7e11b40d415..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode.go +++ /dev/null @@ -1,425 +0,0 @@ -package msgpack - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "io" - "reflect" - "time" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -const bytesAllocLimit = 1024 * 1024 // 1mb - -type bufReader interface { - Read([]byte) (int, error) - ReadByte() (byte, error) - UnreadByte() error -} - -func newBufReader(r io.Reader) bufReader { - if br, ok := r.(bufReader); ok { - return br - } - return bufio.NewReader(r) -} - -func makeBuffer() []byte { - return make([]byte, 0, 64) -} - -// Unmarshal decodes the MessagePack-encoded data and stores the result -// in the value pointed to by v. -func Unmarshal(data []byte, v ...interface{}) error { - return NewDecoder(bytes.NewReader(data)).Decode(v...) -} - -type Decoder struct { - DecodeMapFunc func(*Decoder) (interface{}, error) - - r bufReader - buf []byte - - extLen int - rec []byte // accumulates read data if not nil -} - -func NewDecoder(r io.Reader) *Decoder { - return &Decoder{ - DecodeMapFunc: decodeMap, - - r: newBufReader(r), - buf: makeBuffer(), - } -} - -func (d *Decoder) Reset(r io.Reader) error { - d.r = newBufReader(r) - return nil -} - -func (d *Decoder) Decode(v ...interface{}) error { - for _, vv := range v { - if err := d.decode(vv); err != nil { - return err - } - } - return nil -} - -func (d *Decoder) decode(dst interface{}) error { - var err error - switch v := dst.(type) { - case *string: - if v != nil { - *v, err = d.DecodeString() - return err - } - case *[]byte: - if v != nil { - return d.decodeBytesPtr(v) - } - case *int: - if v != nil { - *v, err = d.DecodeInt() - return err - } - case *int8: - if v != nil { - *v, err = d.DecodeInt8() - return err - } - case *int16: - if v != nil { - *v, err = d.DecodeInt16() - return err - } - case *int32: - if v != nil { - *v, err = d.DecodeInt32() - return err - } - case *int64: - if v != nil { - *v, err = d.DecodeInt64() - return err - } - case *uint: - if v != nil { - *v, err = d.DecodeUint() - return err - } - case *uint8: - if v != nil { - *v, err = d.DecodeUint8() - return err - } - case *uint16: - if v != nil { - *v, err = d.DecodeUint16() - return err - } - case *uint32: - if v != nil { - *v, err = d.DecodeUint32() - return err - } - case *uint64: - if v != nil { - *v, err = d.DecodeUint64() - return err - } - case *bool: - if v != nil { - *v, err = d.DecodeBool() - return err - } - case *float32: - if v != nil { - *v, err = d.DecodeFloat32() - return err - } - case *float64: - if v != nil { - *v, err = d.DecodeFloat64() - return err - } - case *[]string: - return d.decodeStringSlicePtr(v) - case *map[string]string: - return d.decodeMapStringStringPtr(v) - case *map[string]interface{}: - return d.decodeMapStringInterfacePtr(v) - case *time.Duration: - if v != nil { - vv, err := d.DecodeInt64() - *v = time.Duration(vv) - return err - } - case *time.Time: - if v != nil { - *v, err = d.DecodeTime() - return err - } - } - - v := reflect.ValueOf(dst) - if !v.IsValid() { - return errors.New("msgpack: Decode(nil)") - } - if v.Kind() != reflect.Ptr { - return fmt.Errorf("msgpack: Decode(nonsettable %T)", dst) - } - v = v.Elem() - if !v.IsValid() { - return fmt.Errorf("msgpack: Decode(nonsettable %T)", dst) - } - return d.DecodeValue(v) -} - -func (d *Decoder) DecodeValue(v reflect.Value) error { - decode := getDecoder(v.Type()) - return decode(d, v) -} - -func (d *Decoder) DecodeNil() error { - c, err := d.readByte() - if err != nil { - return err - } - if c != codes.Nil { - return fmt.Errorf("msgpack: invalid code %x decoding nil", c) - } - return nil -} - -func (d *Decoder) DecodeBool() (bool, error) { - c, err := d.readByte() - if err != nil { - return false, err - } - return d.bool(c) -} - -func (d *Decoder) bool(c byte) (bool, error) { - if c == codes.False { - return false, nil - } - if c == codes.True { - return true, nil - } - return false, fmt.Errorf("msgpack: invalid code %x decoding bool", c) -} - -func (d *Decoder) interfaceValue(v reflect.Value) error { - vv, err := d.DecodeInterface() - if err != nil { - return err - } - if vv != nil { - if v.Type() == errorType { - if vv, ok := vv.(string); ok { - v.Set(reflect.ValueOf(errors.New(vv))) - return nil - } - } - - v.Set(reflect.ValueOf(vv)) - } - return nil -} - -// DecodeInterface decodes value into interface. Possible value types are: -// - nil, -// - bool, -// - int64 for negative numbers, -// - uint64 for positive numbers, -// - float32 and float64, -// - string, -// - slices of any of the above, -// - maps of any of the above. -func (d *Decoder) DecodeInterface() (interface{}, error) { - c, err := d.readByte() - if err != nil { - return nil, err - } - - if codes.IsFixedNum(c) { - if int8(c) < 0 { - return d.int(c) - } - return d.uint(c) - } - if codes.IsFixedMap(c) { - d.r.UnreadByte() - return d.DecodeMap() - } - if codes.IsFixedArray(c) { - return d.decodeSlice(c) - } - if codes.IsFixedString(c) { - return d.string(c) - } - - switch c { - case codes.Nil: - return nil, nil - case codes.False, codes.True: - return d.bool(c) - case codes.Float: - return d.float32(c) - case codes.Double: - return d.float64(c) - case codes.Uint8, codes.Uint16, codes.Uint32, codes.Uint64: - return d.uint(c) - case codes.Int8, codes.Int16, codes.Int32, codes.Int64: - return d.int(c) - case codes.Bin8, codes.Bin16, codes.Bin32: - return d.bytes(c, nil) - case codes.Str8, codes.Str16, codes.Str32: - return d.string(c) - case codes.Array16, codes.Array32: - return d.decodeSlice(c) - case codes.Map16, codes.Map32: - d.r.UnreadByte() - return d.DecodeMap() - case codes.FixExt1, codes.FixExt2, codes.FixExt4, codes.FixExt8, codes.FixExt16, - codes.Ext8, codes.Ext16, codes.Ext32: - return d.ext(c) - } - - return 0, fmt.Errorf("msgpack: unknown code %x decoding interface{}", c) -} - -// Skip skips next value. -func (d *Decoder) Skip() error { - c, err := d.readByte() - if err != nil { - return err - } - - if codes.IsFixedNum(c) { - return nil - } else if codes.IsFixedMap(c) { - return d.skipMap(c) - } else if codes.IsFixedArray(c) { - return d.skipSlice(c) - } else if codes.IsFixedString(c) { - return d.skipBytes(c) - } - - switch c { - case codes.Nil, codes.False, codes.True: - return nil - case codes.Uint8, codes.Int8: - return d.skipN(1) - case codes.Uint16, codes.Int16: - return d.skipN(2) - case codes.Uint32, codes.Int32, codes.Float: - return d.skipN(4) - case codes.Uint64, codes.Int64, codes.Double: - return d.skipN(8) - case codes.Bin8, codes.Bin16, codes.Bin32: - return d.skipBytes(c) - case codes.Str8, codes.Str16, codes.Str32: - return d.skipBytes(c) - case codes.Array16, codes.Array32: - return d.skipSlice(c) - case codes.Map16, codes.Map32: - return d.skipMap(c) - case codes.FixExt1, codes.FixExt2, codes.FixExt4, codes.FixExt8, codes.FixExt16, codes.Ext8, codes.Ext16, codes.Ext32: - return d.skipExt(c) - } - - return fmt.Errorf("msgpack: unknown code %x", c) -} - -// peekCode returns next MessagePack code. See -// https://github.com/msgpack/msgpack/blob/master/spec.md#formats for details. -func (d *Decoder) PeekCode() (code byte, err error) { - code, err = d.r.ReadByte() - if err != nil { - return 0, err - } - return code, d.r.UnreadByte() -} - -func (d *Decoder) hasNilCode() bool { - code, err := d.PeekCode() - return err == nil && code == codes.Nil -} - -func (d *Decoder) readByte() (byte, error) { - c, err := d.r.ReadByte() - if err != nil { - return 0, err - } - if d.rec != nil { - d.rec = append(d.rec, c) - } - return c, nil -} - -func (d *Decoder) readFull(b []byte) error { - _, err := io.ReadFull(d.r, b) - if err != nil { - return err - } - if d.rec != nil { - d.rec = append(d.rec, b...) - } - return nil -} - -func (d *Decoder) readN(n int) ([]byte, error) { - buf, err := readN(d.r, d.buf, n) - if err != nil { - return nil, err - } - d.buf = buf - if d.rec != nil { - d.rec = append(d.rec, buf...) - } - return buf, nil -} - -func readN(r io.Reader, b []byte, n int) ([]byte, error) { - if n == 0 && b == nil { - return make([]byte, 0), nil - } - - if cap(b) >= n { - b = b[:n] - _, err := io.ReadFull(r, b) - return b, err - } - b = b[:cap(b)] - - pos := 0 - for len(b) < n { - diff := n - len(b) - if diff > bytesAllocLimit { - diff = bytesAllocLimit - } - b = append(b, make([]byte, diff)...) - - _, err := io.ReadFull(r, b[pos:]) - if err != nil { - return nil, err - } - - pos = len(b) - } - - return b, nil -} - -func min(a, b int) int { - if a <= b { - return a - } - return b -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_map.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_map.go deleted file mode 100644 index 21c97978d5d..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_map.go +++ /dev/null @@ -1,265 +0,0 @@ -package msgpack - -import ( - "fmt" - "reflect" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -const mapElemsAllocLimit = 1e4 - -var mapStringStringPtrType = reflect.TypeOf((*map[string]string)(nil)) -var mapStringStringType = mapStringStringPtrType.Elem() - -var mapStringInterfacePtrType = reflect.TypeOf((*map[string]interface{})(nil)) -var mapStringInterfaceType = mapStringInterfacePtrType.Elem() - -func decodeMapValue(d *Decoder, v reflect.Value) error { - n, err := d.DecodeMapLen() - if err != nil { - return err - } - - typ := v.Type() - if n == -1 { - v.Set(reflect.Zero(typ)) - return nil - } - - if v.IsNil() { - v.Set(reflect.MakeMap(typ)) - } - keyType := typ.Key() - valueType := typ.Elem() - - for i := 0; i < n; i++ { - mk := reflect.New(keyType).Elem() - if err := d.DecodeValue(mk); err != nil { - return err - } - - mv := reflect.New(valueType).Elem() - if err := d.DecodeValue(mv); err != nil { - return err - } - - v.SetMapIndex(mk, mv) - } - - return nil -} -func decodeMap(d *Decoder) (interface{}, error) { - n, err := d.DecodeMapLen() - if err != nil { - return nil, err - } - if n == -1 { - return nil, nil - } - - m := make(map[interface{}]interface{}, min(n, mapElemsAllocLimit)) - for i := 0; i < n; i++ { - mk, err := d.DecodeInterface() - if err != nil { - return nil, err - } - mv, err := d.DecodeInterface() - if err != nil { - return nil, err - } - m[mk] = mv - } - return m, nil -} - -func (d *Decoder) DecodeMapLen() (int, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - - if codes.IsExt(c) { - if err = d.skipExtHeader(c); err != nil { - return 0, err - } - - c, err = d.readByte() - if err != nil { - return 0, err - } - } - - return d.mapLen(c) -} - -func (d *Decoder) mapLen(c byte) (int, error) { - if c == codes.Nil { - return -1, nil - } - if c >= codes.FixedMapLow && c <= codes.FixedMapHigh { - return int(c & codes.FixedMapMask), nil - } - if c == codes.Map16 { - n, err := d.uint16() - return int(n), err - } - if c == codes.Map32 { - n, err := d.uint32() - return int(n), err - } - return 0, fmt.Errorf("msgpack: invalid code %x decoding map length", c) -} - -func decodeMapStringStringValue(d *Decoder, v reflect.Value) error { - mptr := v.Addr().Convert(mapStringStringPtrType).Interface().(*map[string]string) - return d.decodeMapStringStringPtr(mptr) -} - -func (d *Decoder) decodeMapStringStringPtr(ptr *map[string]string) error { - n, err := d.DecodeMapLen() - if err != nil { - return err - } - if n == -1 { - *ptr = nil - return nil - } - - m := *ptr - if m == nil { - *ptr = make(map[string]string, min(n, mapElemsAllocLimit)) - m = *ptr - } - - for i := 0; i < n; i++ { - mk, err := d.DecodeString() - if err != nil { - return err - } - mv, err := d.DecodeString() - if err != nil { - return err - } - m[mk] = mv - } - - return nil -} - -func decodeMapStringInterfaceValue(d *Decoder, v reflect.Value) error { - ptr := v.Addr().Convert(mapStringInterfacePtrType).Interface().(*map[string]interface{}) - return d.decodeMapStringInterfacePtr(ptr) -} - -func (d *Decoder) decodeMapStringInterfacePtr(ptr *map[string]interface{}) error { - n, err := d.DecodeMapLen() - if err != nil { - return err - } - if n == -1 { - *ptr = nil - return nil - } - - m := *ptr - if m == nil { - *ptr = make(map[string]interface{}, min(n, mapElemsAllocLimit)) - m = *ptr - } - - for i := 0; i < n; i++ { - mk, err := d.DecodeString() - if err != nil { - return err - } - mv, err := d.DecodeInterface() - if err != nil { - return err - } - m[mk] = mv - } - - return nil -} - -func (d *Decoder) DecodeMap() (interface{}, error) { - return d.DecodeMapFunc(d) -} - -func (d *Decoder) skipMap(c byte) error { - n, err := d.mapLen(c) - if err != nil { - return err - } - for i := 0; i < n; i++ { - if err := d.Skip(); err != nil { - return err - } - if err := d.Skip(); err != nil { - return err - } - } - return nil -} - -func decodeStructValue(d *Decoder, strct reflect.Value) error { - c, err := d.readByte() - if err != nil { - return err - } - - var isArray bool - - n, err := d.mapLen(c) - if err != nil { - var err2 error - n, err2 = d.arrayLen(c) - if err2 != nil { - return err - } - isArray = true - } - if n == -1 { - strct.Set(reflect.Zero(strct.Type())) - return nil - } - - fields := structs.Fields(strct.Type()) - - if isArray { - for i, f := range fields.List { - if i >= n { - break - } - if err := f.DecodeValue(d, strct); err != nil { - return err - } - } - // Skip extra values. - for i := len(fields.List); i < n; i++ { - if err := d.Skip(); err != nil { - return err - } - } - return nil - } - - for i := 0; i < n; i++ { - name, err := d.DecodeString() - if err != nil { - return err - } - if f := fields.Table[name]; f != nil { - if err := f.DecodeValue(d, strct); err != nil { - return err - } - } else { - if err := d.Skip(); err != nil { - return err - } - } - } - - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_number.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_number.go deleted file mode 100644 index 587634161c1..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_number.go +++ /dev/null @@ -1,270 +0,0 @@ -package msgpack - -import ( - "fmt" - "math" - "reflect" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -func (d *Decoder) skipN(n int) error { - _, err := d.readN(n) - return err -} - -func (d *Decoder) uint8() (uint8, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return uint8(c), nil -} - -func (d *Decoder) uint16() (uint16, error) { - b, err := d.readN(2) - if err != nil { - return 0, err - } - return (uint16(b[0]) << 8) | uint16(b[1]), nil -} - -func (d *Decoder) uint32() (uint32, error) { - b, err := d.readN(4) - if err != nil { - return 0, err - } - n := (uint32(b[0]) << 24) | - (uint32(b[1]) << 16) | - (uint32(b[2]) << 8) | - uint32(b[3]) - return n, nil -} - -func (d *Decoder) uint64() (uint64, error) { - b, err := d.readN(8) - if err != nil { - return 0, err - } - n := (uint64(b[0]) << 56) | - (uint64(b[1]) << 48) | - (uint64(b[2]) << 40) | - (uint64(b[3]) << 32) | - (uint64(b[4]) << 24) | - (uint64(b[5]) << 16) | - (uint64(b[6]) << 8) | - uint64(b[7]) - return n, nil -} - -func (d *Decoder) DecodeUint64() (uint64, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return d.uint(c) -} - -func (d *Decoder) uint(c byte) (uint64, error) { - if c == codes.Nil { - return 0, nil - } - if codes.IsFixedNum(c) { - return uint64(int8(c)), nil - } - switch c { - case codes.Uint8: - n, err := d.uint8() - return uint64(n), err - case codes.Int8: - n, err := d.uint8() - return uint64(int8(n)), err - case codes.Uint16: - n, err := d.uint16() - return uint64(n), err - case codes.Int16: - n, err := d.uint16() - return uint64(int16(n)), err - case codes.Uint32: - n, err := d.uint32() - return uint64(n), err - case codes.Int32: - n, err := d.uint32() - return uint64(int32(n)), err - case codes.Uint64, codes.Int64: - return d.uint64() - } - return 0, fmt.Errorf("msgpack: invalid code %x decoding uint64", c) -} - -func (d *Decoder) DecodeInt64() (int64, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return d.int(c) -} - -func (d *Decoder) int(c byte) (int64, error) { - if c == codes.Nil { - return 0, nil - } - if codes.IsFixedNum(c) { - return int64(int8(c)), nil - } - switch c { - case codes.Uint8: - n, err := d.uint8() - return int64(n), err - case codes.Int8: - n, err := d.uint8() - return int64(int8(n)), err - case codes.Uint16: - n, err := d.uint16() - return int64(n), err - case codes.Int16: - n, err := d.uint16() - return int64(int16(n)), err - case codes.Uint32: - n, err := d.uint32() - return int64(n), err - case codes.Int32: - n, err := d.uint32() - return int64(int32(n)), err - case codes.Uint64, codes.Int64: - n, err := d.uint64() - return int64(n), err - } - return 0, fmt.Errorf("msgpack: invalid code %x decoding int64", c) -} - -func (d *Decoder) DecodeFloat32() (float32, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return d.float32(c) -} - -func (d *Decoder) float32(c byte) (float32, error) { - if c == codes.Float { - n, err := d.uint32() - if err != nil { - return 0, err - } - return math.Float32frombits(n), nil - } - - n, err := d.int(c) - if err != nil { - return 0, fmt.Errorf("msgpack: invalid code %x decoding float32", c) - } - return float32(n), nil -} - -func (d *Decoder) DecodeFloat64() (float64, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return d.float64(c) -} - -func (d *Decoder) float64(c byte) (float64, error) { - switch c { - case codes.Float: - n, err := d.float32(c) - if err != nil { - return 0, err - } - return float64(n), nil - case codes.Double: - n, err := d.uint64() - if err != nil { - return 0, err - } - return math.Float64frombits(n), nil - } - - n, err := d.int(c) - if err != nil { - return 0, fmt.Errorf("msgpack: invalid code %x decoding float32", c) - } - return float64(n), nil -} - -func (d *Decoder) DecodeUint() (uint, error) { - n, err := d.DecodeUint64() - return uint(n), err -} - -func (d *Decoder) DecodeUint8() (uint8, error) { - n, err := d.DecodeUint64() - return uint8(n), err -} - -func (d *Decoder) DecodeUint16() (uint16, error) { - n, err := d.DecodeUint64() - return uint16(n), err -} - -func (d *Decoder) DecodeUint32() (uint32, error) { - n, err := d.DecodeUint64() - return uint32(n), err -} - -func (d *Decoder) DecodeInt() (int, error) { - n, err := d.DecodeInt64() - return int(n), err -} - -func (d *Decoder) DecodeInt8() (int8, error) { - n, err := d.DecodeInt64() - return int8(n), err -} - -func (d *Decoder) DecodeInt16() (int16, error) { - n, err := d.DecodeInt64() - return int16(n), err -} - -func (d *Decoder) DecodeInt32() (int32, error) { - n, err := d.DecodeInt64() - return int32(n), err -} - -func decodeFloat32Value(d *Decoder, v reflect.Value) error { - f, err := d.DecodeFloat32() - if err != nil { - return err - } - v.SetFloat(float64(f)) - return nil -} - -func decodeFloat64Value(d *Decoder, v reflect.Value) error { - f, err := d.DecodeFloat64() - if err != nil { - return err - } - v.SetFloat(f) - return nil -} - -func decodeInt64Value(d *Decoder, v reflect.Value) error { - n, err := d.DecodeInt64() - if err != nil { - return err - } - v.SetInt(n) - return nil -} - -func decodeUint64Value(d *Decoder, v reflect.Value) error { - n, err := d.DecodeUint64() - if err != nil { - return err - } - v.SetUint(n) - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_query.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_query.go deleted file mode 100644 index 18d9d89b938..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_query.go +++ /dev/null @@ -1,158 +0,0 @@ -package msgpack - -import ( - "fmt" - "strconv" - "strings" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -type queryResult struct { - query string - key string - hasAsterisk bool - - values []interface{} -} - -func (q *queryResult) nextKey() { - ind := strings.IndexByte(q.query, '.') - if ind == -1 { - q.key = q.query - q.query = "" - return - } - q.key = q.query[:ind] - q.query = q.query[ind+1:] -} - -// Query extracts data specified by the query from the msgpack stream skipping -// any other data. Query consists of map keys and array indexes separated with dot, -// e.g. key1.0.key2. -func (d *Decoder) Query(query string) ([]interface{}, error) { - res := queryResult{ - query: query, - } - if err := d.query(&res); err != nil { - return nil, err - } - return res.values, nil -} - -func (d *Decoder) query(q *queryResult) error { - q.nextKey() - if q.key == "" { - v, err := d.DecodeInterface() - if err != nil { - return err - } - q.values = append(q.values, v) - return nil - } - - code, err := d.PeekCode() - if err != nil { - return err - } - - switch { - case code == codes.Map16 || code == codes.Map32 || codes.IsFixedMap(code): - err = d.queryMapKey(q) - case code == codes.Array16 || code == codes.Array32 || codes.IsFixedArray(code): - err = d.queryArrayIndex(q) - default: - err = fmt.Errorf("msgpack: unsupported code=%x decoding key=%q", code, q.key) - } - return err -} - -func (d *Decoder) queryMapKey(q *queryResult) error { - n, err := d.DecodeMapLen() - if err != nil { - return err - } - if n == -1 { - return nil - } - - for i := 0; i < n; i++ { - k, err := d.bytesNoCopy() - if err != nil { - return err - } - - if string(k) == q.key { - if err := d.query(q); err != nil { - return err - } - if q.hasAsterisk { - return d.skipNext((n - i - 1) * 2) - } - return nil - } - - if err := d.Skip(); err != nil { - return err - } - } - - return nil -} - -func (d *Decoder) queryArrayIndex(q *queryResult) error { - n, err := d.DecodeSliceLen() - if err != nil { - return err - } - if n == -1 { - return nil - } - - if q.key == "*" { - q.hasAsterisk = true - - query := q.query - for i := 0; i < n; i++ { - q.query = query - if err := d.query(q); err != nil { - return err - } - } - - q.hasAsterisk = false - return nil - } - - ind, err := strconv.Atoi(q.key) - if err != nil { - return err - } - - for i := 0; i < n; i++ { - if i == ind { - if err := d.query(q); err != nil { - return err - } - if q.hasAsterisk { - return d.skipNext(n - i - 1) - } - return nil - } - - if err := d.Skip(); err != nil { - return err - } - } - - return nil -} - -func (d *Decoder) skipNext(n int) error { - for i := 0; i < n; i++ { - if err := d.Skip(); err != nil { - return err - } - } - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_slice.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_slice.go deleted file mode 100644 index 61e3da2bd44..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_slice.go +++ /dev/null @@ -1,197 +0,0 @@ -package msgpack - -import ( - "fmt" - "reflect" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -const sliceElemsAllocLimit = 1e4 - -var sliceStringPtrType = reflect.TypeOf((*[]string)(nil)) - -// Deprecated. Use DecodeArrayLen instead. -func (d *Decoder) DecodeSliceLen() (int, error) { - return d.DecodeArrayLen() -} - -func (d *Decoder) DecodeArrayLen() (int, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return d.arrayLen(c) -} - -func (d *Decoder) arrayLen(c byte) (int, error) { - if c == codes.Nil { - return -1, nil - } else if c >= codes.FixedArrayLow && c <= codes.FixedArrayHigh { - return int(c & codes.FixedArrayMask), nil - } - switch c { - case codes.Array16: - n, err := d.uint16() - return int(n), err - case codes.Array32: - n, err := d.uint32() - return int(n), err - } - return 0, fmt.Errorf("msgpack: invalid code %x decoding array length", c) -} - -func decodeStringSliceValue(d *Decoder, v reflect.Value) error { - ptr := v.Addr().Convert(sliceStringPtrType).Interface().(*[]string) - return d.decodeStringSlicePtr(ptr) -} - -func (d *Decoder) decodeStringSlicePtr(ptr *[]string) error { - n, err := d.DecodeArrayLen() - if err != nil { - return err - } - if n == -1 { - return nil - } - - ss := setStringsCap(*ptr, n) - for i := 0; i < n; i++ { - s, err := d.DecodeString() - if err != nil { - return err - } - ss = append(ss, s) - } - *ptr = ss - - return nil -} - -func setStringsCap(s []string, n int) []string { - if n > sliceElemsAllocLimit { - n = sliceElemsAllocLimit - } - - if s == nil { - return make([]string, 0, n) - } - - if cap(s) >= n { - return s[:0] - } - - s = s[:cap(s)] - s = append(s, make([]string, n-len(s))...) - return s[:0] -} - -func decodeSliceValue(d *Decoder, v reflect.Value) error { - n, err := d.DecodeArrayLen() - if err != nil { - return err - } - - if n == -1 { - v.Set(reflect.Zero(v.Type())) - return nil - } - if n == 0 && v.IsNil() { - v.Set(reflect.MakeSlice(v.Type(), 0, 0)) - return nil - } - - if v.Cap() >= n { - v.Set(v.Slice(0, n)) - } else if v.Len() < v.Cap() { - v.Set(v.Slice(0, v.Cap())) - } - - for i := 0; i < n; i++ { - if i >= v.Len() { - v.Set(growSliceValue(v, n)) - } - sv := v.Index(i) - if err := d.DecodeValue(sv); err != nil { - return err - } - } - - return nil -} - -func growSliceValue(v reflect.Value, n int) reflect.Value { - diff := n - v.Len() - if diff > sliceElemsAllocLimit { - diff = sliceElemsAllocLimit - } - v = reflect.AppendSlice(v, reflect.MakeSlice(v.Type(), diff, diff)) - return v -} - -func decodeArrayValue(d *Decoder, v reflect.Value) error { - n, err := d.DecodeArrayLen() - if err != nil { - return err - } - - if n == -1 { - return nil - } - - if n > v.Len() { - return fmt.Errorf("%s len is %d, but msgpack has %d elements", v.Type(), v.Len(), n) - } - for i := 0; i < n; i++ { - sv := v.Index(i) - if err := d.DecodeValue(sv); err != nil { - return err - } - } - - return nil -} - -func (d *Decoder) DecodeSlice() ([]interface{}, error) { - c, err := d.readByte() - if err != nil { - return nil, err - } - return d.decodeSlice(c) -} - -func (d *Decoder) decodeSlice(c byte) ([]interface{}, error) { - n, err := d.arrayLen(c) - if err != nil { - return nil, err - } - if n == -1 { - return nil, nil - } - - s := make([]interface{}, 0, min(n, sliceElemsAllocLimit)) - for i := 0; i < n; i++ { - v, err := d.DecodeInterface() - if err != nil { - return nil, err - } - s = append(s, v) - } - - return s, nil -} - -func (d *Decoder) skipSlice(c byte) error { - n, err := d.arrayLen(c) - if err != nil { - return err - } - - for i := 0; i < n; i++ { - if err := d.Skip(); err != nil { - return err - } - } - - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_string.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_string.go deleted file mode 100644 index 17c1b6118ed..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_string.go +++ /dev/null @@ -1,168 +0,0 @@ -package msgpack - -import ( - "fmt" - "reflect" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -func (d *Decoder) bytesLen(c byte) (int, error) { - if c == codes.Nil { - return -1, nil - } else if codes.IsFixedString(c) { - return int(c & codes.FixedStrMask), nil - } - switch c { - case codes.Str8, codes.Bin8: - n, err := d.uint8() - return int(n), err - case codes.Str16, codes.Bin16: - n, err := d.uint16() - return int(n), err - case codes.Str32, codes.Bin32: - n, err := d.uint32() - return int(n), err - } - return 0, fmt.Errorf("msgpack: invalid code %x decoding bytes length", c) -} - -func (d *Decoder) DecodeString() (string, error) { - c, err := d.readByte() - if err != nil { - return "", err - } - return d.string(c) -} - -func (d *Decoder) string(c byte) (string, error) { - n, err := d.bytesLen(c) - if err != nil { - return "", err - } - if n == -1 { - return "", nil - } - b, err := d.readN(n) - return string(b), err -} - -func decodeStringValue(d *Decoder, v reflect.Value) error { - s, err := d.DecodeString() - if err != nil { - return err - } - v.SetString(s) - return nil -} - -func (d *Decoder) DecodeBytesLen() (int, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return d.bytesLen(c) -} - -func (d *Decoder) DecodeBytes() ([]byte, error) { - c, err := d.readByte() - if err != nil { - return nil, err - } - return d.bytes(c, nil) -} - -func (d *Decoder) bytes(c byte, b []byte) ([]byte, error) { - n, err := d.bytesLen(c) - if err != nil { - return nil, err - } - if n == -1 { - return nil, nil - } - return readN(d.r, b, n) -} - -func (d *Decoder) bytesNoCopy() ([]byte, error) { - c, err := d.readByte() - if err != nil { - return nil, err - } - n, err := d.bytesLen(c) - if err != nil { - return nil, err - } - if n == -1 { - return nil, nil - } - return d.readN(n) -} - -func (d *Decoder) decodeBytesPtr(ptr *[]byte) error { - c, err := d.readByte() - if err != nil { - return err - } - return d.bytesPtr(c, ptr) -} - -func (d *Decoder) bytesPtr(c byte, ptr *[]byte) error { - n, err := d.bytesLen(c) - if err != nil { - return err - } - if n == -1 { - *ptr = nil - return nil - } - - *ptr, err = readN(d.r, *ptr, n) - return err -} - -func (d *Decoder) skipBytes(c byte) error { - n, err := d.bytesLen(c) - if err != nil { - return err - } - if n == -1 { - return nil - } - return d.skipN(n) -} - -func decodeBytesValue(d *Decoder, v reflect.Value) error { - c, err := d.readByte() - if err != nil { - return err - } - - b, err := d.bytes(c, v.Bytes()) - if err != nil { - return err - } - v.SetBytes(b) - - return nil -} - -func decodeByteArrayValue(d *Decoder, v reflect.Value) error { - c, err := d.readByte() - if err != nil { - return err - } - - n, err := d.bytesLen(c) - if err != nil { - return err - } - if n == -1 { - return nil - } - if n > v.Len() { - return fmt.Errorf("%s len is %d, but msgpack has %d elements", v.Type(), v.Len(), n) - } - - b := v.Slice(0, n).Bytes() - return d.readFull(b) -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_value.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_value.go deleted file mode 100644 index e239296238f..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/decode_value.go +++ /dev/null @@ -1,248 +0,0 @@ -package msgpack - -import ( - "fmt" - "reflect" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -var interfaceType = reflect.TypeOf((*interface{})(nil)).Elem() -var stringType = reflect.TypeOf((*string)(nil)).Elem() - -var valueDecoders []decoderFunc - -func init() { - valueDecoders = []decoderFunc{ - reflect.Bool: decodeBoolValue, - reflect.Int: decodeInt64Value, - reflect.Int8: decodeInt64Value, - reflect.Int16: decodeInt64Value, - reflect.Int32: decodeInt64Value, - reflect.Int64: decodeInt64Value, - reflect.Uint: decodeUint64Value, - reflect.Uint8: decodeUint64Value, - reflect.Uint16: decodeUint64Value, - reflect.Uint32: decodeUint64Value, - reflect.Uint64: decodeUint64Value, - reflect.Float32: decodeFloat32Value, - reflect.Float64: decodeFloat64Value, - reflect.Complex64: decodeUnsupportedValue, - reflect.Complex128: decodeUnsupportedValue, - reflect.Array: decodeArrayValue, - reflect.Chan: decodeUnsupportedValue, - reflect.Func: decodeUnsupportedValue, - reflect.Interface: decodeInterfaceValue, - reflect.Map: decodeMapValue, - reflect.Ptr: decodeUnsupportedValue, - reflect.Slice: decodeSliceValue, - reflect.String: decodeStringValue, - reflect.Struct: decodeStructValue, - reflect.UnsafePointer: decodeUnsupportedValue, - } -} - -func getDecoder(typ reflect.Type) decoderFunc { - kind := typ.Kind() - - if decoder, ok := typDecMap[typ]; ok { - return decoder - } - - if typ.Implements(customDecoderType) { - return decodeCustomValue - } - if typ.Implements(unmarshalerType) { - return unmarshalValue - } - - // Addressable struct field value. - if kind != reflect.Ptr { - ptr := reflect.PtrTo(typ) - if ptr.Implements(customDecoderType) { - return decodeCustomValueAddr - } - if ptr.Implements(unmarshalerType) { - return unmarshalValueAddr - } - } - - switch kind { - case reflect.Ptr: - return ptrDecoderFunc(typ) - case reflect.Slice: - elem := typ.Elem() - switch elem.Kind() { - case reflect.Uint8: - return decodeBytesValue - } - switch elem { - case stringType: - return decodeStringSliceValue - } - case reflect.Array: - if typ.Elem().Kind() == reflect.Uint8 { - return decodeByteArrayValue - } - case reflect.Map: - if typ.Key() == stringType { - switch typ.Elem() { - case stringType: - return decodeMapStringStringValue - case interfaceType: - return decodeMapStringInterfaceValue - } - } - } - return valueDecoders[kind] -} - -func ptrDecoderFunc(typ reflect.Type) decoderFunc { - decoder := getDecoder(typ.Elem()) - return func(d *Decoder, v reflect.Value) error { - if d.hasNilCode() { - v.Set(reflect.Zero(v.Type())) - return d.DecodeNil() - } - if v.IsNil() { - if !v.CanSet() { - return fmt.Errorf("msgpack: Decode(nonsettable %T)", v.Interface()) - } - v.Set(reflect.New(v.Type().Elem())) - } - return decoder(d, v.Elem()) - } -} - -func decodeCustomValueAddr(d *Decoder, v reflect.Value) error { - if !v.CanAddr() { - return fmt.Errorf("msgpack: Decode(nonsettable %T)", v.Interface()) - } - return decodeCustomValue(d, v.Addr()) -} - -func decodeCustomValue(d *Decoder, v reflect.Value) error { - c, err := d.PeekCode() - if err != nil { - return err - } - - if codes.IsExt(c) { - c, err = d.readByte() - if err != nil { - return err - } - - _, err = d.parseExtLen(c) - if err != nil { - return err - } - - _, err = d.readByte() - if err != nil { - return err - } - - c, err = d.PeekCode() - if err != nil { - return err - } - } - - if c == codes.Nil { - // TODO: set nil - return d.DecodeNil() - } - - if v.IsNil() { - v.Set(reflect.New(v.Type().Elem())) - } - - decoder := v.Interface().(CustomDecoder) - return decoder.DecodeMsgpack(d) -} - -func unmarshalValueAddr(d *Decoder, v reflect.Value) error { - if !v.CanAddr() { - return fmt.Errorf("msgpack: Decode(nonsettable %T)", v.Interface()) - } - return unmarshalValue(d, v.Addr()) -} - -func unmarshalValue(d *Decoder, v reflect.Value) error { - c, err := d.PeekCode() - if err != nil { - return err - } - - if codes.IsExt(c) { - c, err = d.readByte() - if err != nil { - return err - } - - extLen, err := d.parseExtLen(c) - if err != nil { - return err - } - d.extLen = extLen - - _, err = d.readByte() - if err != nil { - return err - } - - c, err = d.PeekCode() - if err != nil { - return err - } - } - - if c == codes.Nil { - // TODO: set nil - return d.DecodeNil() - } - - if v.IsNil() { - v.Set(reflect.New(v.Type().Elem())) - } - - if d.extLen != 0 { - b, err := d.readN(d.extLen) - d.extLen = 0 - if err != nil { - return err - } - d.rec = b - } else { - d.rec = makeBuffer() - if err := d.Skip(); err != nil { - return err - } - } - - unmarshaler := v.Interface().(Unmarshaler) - err = unmarshaler.UnmarshalMsgpack(d.rec) - d.rec = nil - return err -} - -func decodeBoolValue(d *Decoder, v reflect.Value) error { - flag, err := d.DecodeBool() - if err != nil { - return err - } - v.SetBool(flag) - return nil -} - -func decodeInterfaceValue(d *Decoder, v reflect.Value) error { - if v.IsNil() { - return d.interfaceValue(v) - } - return d.DecodeValue(v.Elem()) -} - -func decodeUnsupportedValue(d *Decoder, v reflect.Value) error { - return fmt.Errorf("msgpack: Decode(unsupported %s)", v.Type()) -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/encode.go deleted file mode 100644 index ad10f2e9a6f..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode.go +++ /dev/null @@ -1,144 +0,0 @@ -package msgpack - -import ( - "bytes" - "io" - "reflect" - "time" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -type writer interface { - io.Writer - WriteByte(byte) error - WriteString(string) (int, error) -} - -type byteWriter struct { - io.Writer -} - -func (w byteWriter) WriteByte(b byte) error { - _, err := w.Write([]byte{b}) - return err -} - -func (w byteWriter) WriteString(s string) (int, error) { - return w.Write([]byte(s)) -} - -// Marshal returns the MessagePack encoding of v. -func Marshal(v ...interface{}) ([]byte, error) { - var buf bytes.Buffer - err := NewEncoder(&buf).Encode(v...) - return buf.Bytes(), err -} - -type Encoder struct { - w writer - buf []byte - - sortMapKeys bool - structAsArray bool -} - -func NewEncoder(w io.Writer) *Encoder { - bw, ok := w.(writer) - if !ok { - bw = byteWriter{Writer: w} - } - return &Encoder{ - w: bw, - buf: make([]byte, 9), - } -} - -// SortMapKeys causes the Encoder to encode map keys in increasing order. -// Supported map types are: -// - map[string]string -// - map[string]interface{} -func (e *Encoder) SortMapKeys(v bool) *Encoder { - e.sortMapKeys = v - return e -} - -// StructAsArray causes the Encoder to encode Go structs as MessagePack arrays. -func (e *Encoder) StructAsArray(v bool) *Encoder { - e.structAsArray = v - return e -} - -func (e *Encoder) Encode(v ...interface{}) error { - for _, vv := range v { - if err := e.encode(vv); err != nil { - return err - } - } - return nil -} - -func (e *Encoder) encode(v interface{}) error { - switch v := v.(type) { - case nil: - return e.EncodeNil() - case string: - return e.EncodeString(v) - case []byte: - return e.EncodeBytes(v) - case int: - return e.EncodeInt64(int64(v)) - case int64: - return e.EncodeInt64(v) - case uint: - return e.EncodeUint64(uint64(v)) - case uint64: - return e.EncodeUint64(v) - case bool: - return e.EncodeBool(v) - case float32: - return e.EncodeFloat32(v) - case float64: - return e.EncodeFloat64(v) - case time.Duration: - return e.EncodeInt64(int64(v)) - case time.Time: - return e.EncodeTime(v) - } - return e.EncodeValue(reflect.ValueOf(v)) -} - -func (e *Encoder) EncodeValue(v reflect.Value) error { - encode := getEncoder(v.Type()) - return encode(e, v) -} - -func (e *Encoder) EncodeNil() error { - return e.w.WriteByte(codes.Nil) -} - -func (e *Encoder) EncodeBool(value bool) error { - if value { - return e.w.WriteByte(codes.True) - } - return e.w.WriteByte(codes.False) -} - -func (e *Encoder) write(b []byte) error { - _, err := e.w.Write(b) - if err != nil { - return err - } - return nil -} - -func (e *Encoder) writeString(s string) error { - n, err := e.w.WriteString(s) - if err != nil { - return err - } - if n < len(s) { - return io.ErrShortWrite - } - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_map.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_map.go deleted file mode 100644 index c9544ccfae2..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_map.go +++ /dev/null @@ -1,166 +0,0 @@ -package msgpack - -import ( - "reflect" - "sort" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -func encodeMapValue(e *Encoder, v reflect.Value) error { - if v.IsNil() { - return e.EncodeNil() - } - - if err := e.EncodeMapLen(v.Len()); err != nil { - return err - } - - for _, key := range v.MapKeys() { - if err := e.EncodeValue(key); err != nil { - return err - } - if err := e.EncodeValue(v.MapIndex(key)); err != nil { - return err - } - } - - return nil -} - -func encodeMapStringStringValue(e *Encoder, v reflect.Value) error { - if v.IsNil() { - return e.EncodeNil() - } - - if err := e.EncodeMapLen(v.Len()); err != nil { - return err - } - - m := v.Convert(mapStringStringType).Interface().(map[string]string) - if e.sortMapKeys { - return e.encodeSortedMapStringString(m) - } - - for mk, mv := range m { - if err := e.EncodeString(mk); err != nil { - return err - } - if err := e.EncodeString(mv); err != nil { - return err - } - } - - return nil -} - -func encodeMapStringInterfaceValue(e *Encoder, v reflect.Value) error { - if v.IsNil() { - return e.EncodeNil() - } - - if err := e.EncodeMapLen(v.Len()); err != nil { - return err - } - - m := v.Convert(mapStringInterfaceType).Interface().(map[string]interface{}) - if e.sortMapKeys { - return e.encodeSortedMapStringInterface(m) - } - - for mk, mv := range m { - if err := e.EncodeString(mk); err != nil { - return err - } - if err := e.Encode(mv); err != nil { - return err - } - } - - return nil -} - -func (e *Encoder) encodeSortedMapStringString(m map[string]string) error { - keys := make([]string, 0, len(m)) - for k, _ := range m { - keys = append(keys, k) - } - sort.Strings(keys) - - for _, k := range keys { - err := e.EncodeString(k) - if err != nil { - return err - } - if err = e.EncodeString(m[k]); err != nil { - return err - } - } - - return nil -} - -func (e *Encoder) encodeSortedMapStringInterface(m map[string]interface{}) error { - keys := make([]string, 0, len(m)) - for k, _ := range m { - keys = append(keys, k) - } - sort.Strings(keys) - - for _, k := range keys { - err := e.EncodeString(k) - if err != nil { - return err - } - if err = e.Encode(m[k]); err != nil { - return err - } - } - - return nil -} - -func (e *Encoder) EncodeMapLen(l int) error { - if l < 16 { - return e.w.WriteByte(codes.FixedMapLow | byte(l)) - } - if l < 65536 { - return e.write2(codes.Map16, uint64(l)) - } - return e.write4(codes.Map32, uint32(l)) -} - -func encodeStructValue(e *Encoder, strct reflect.Value) error { - structFields := structs.Fields(strct.Type()) - if e.structAsArray || structFields.asArray { - return encodeStructValueAsArray(e, strct, structFields.List) - } - fields := structFields.OmitEmpty(strct) - - if err := e.EncodeMapLen(len(fields)); err != nil { - return err - } - - for _, f := range fields { - if err := e.EncodeString(f.name); err != nil { - return err - } - if err := f.EncodeValue(e, strct); err != nil { - return err - } - } - - return nil -} - -func encodeStructValueAsArray(e *Encoder, strct reflect.Value, fields []*field) error { - if err := e.EncodeArrayLen(len(fields)); err != nil { - return err - } - for _, f := range fields { - if err := f.EncodeValue(e, strct); err != nil { - return err - } - } - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_number.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_number.go deleted file mode 100644 index 347f56ca5d4..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_number.go +++ /dev/null @@ -1,138 +0,0 @@ -package msgpack - -import ( - "math" - "reflect" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -func (e *Encoder) EncodeUint(v uint) error { - return e.EncodeUint64(uint64(v)) -} - -func (e *Encoder) EncodeUint8(v uint8) error { - return e.EncodeUint64(uint64(v)) -} - -func (e *Encoder) EncodeUint16(v uint16) error { - return e.EncodeUint64(uint64(v)) -} - -func (e *Encoder) EncodeUint32(v uint32) error { - return e.EncodeUint64(uint64(v)) -} - -func (e *Encoder) EncodeUint64(v uint64) error { - if v <= math.MaxInt8 { - return e.w.WriteByte(byte(v)) - } - if v <= math.MaxUint8 { - return e.write1(codes.Uint8, v) - } - if v <= math.MaxUint16 { - return e.write2(codes.Uint16, v) - } - if v <= math.MaxUint32 { - return e.write4(codes.Uint32, uint32(v)) - } - return e.write8(codes.Uint64, v) -} - -func (e *Encoder) EncodeInt(v int) error { - return e.EncodeInt64(int64(v)) -} - -func (e *Encoder) EncodeInt8(v int8) error { - return e.EncodeInt64(int64(v)) -} - -func (e *Encoder) EncodeInt16(v int16) error { - return e.EncodeInt64(int64(v)) -} - -func (e *Encoder) EncodeInt32(v int32) error { - return e.EncodeInt64(int64(v)) -} - -func (e *Encoder) EncodeInt64(v int64) error { - if v >= 0 { - return e.EncodeUint64(uint64(v)) - } - if v >= int64(int8(codes.NegFixedNumLow)) { - return e.w.WriteByte(byte(v)) - } - if v >= math.MinInt8 { - return e.write1(codes.Int8, uint64(v)) - } - if v >= math.MinInt16 { - return e.write2(codes.Int16, uint64(v)) - } - if v >= math.MinInt32 { - return e.write4(codes.Int32, uint32(v)) - } - return e.write8(codes.Int64, uint64(v)) -} - -func (e *Encoder) EncodeFloat32(n float32) error { - return e.write4(codes.Float, math.Float32bits(n)) -} - -func (e *Encoder) EncodeFloat64(n float64) error { - return e.write8(codes.Double, math.Float64bits(n)) -} - -func (e *Encoder) write1(code byte, n uint64) error { - e.buf = e.buf[:2] - e.buf[0] = code - e.buf[1] = byte(n) - return e.write(e.buf) -} - -func (e *Encoder) write2(code byte, n uint64) error { - e.buf = e.buf[:3] - e.buf[0] = code - e.buf[1] = byte(n >> 8) - e.buf[2] = byte(n) - return e.write(e.buf) -} - -func (e *Encoder) write4(code byte, n uint32) error { - e.buf = e.buf[:5] - e.buf[0] = code - e.buf[1] = byte(n >> 24) - e.buf[2] = byte(n >> 16) - e.buf[3] = byte(n >> 8) - e.buf[4] = byte(n) - return e.write(e.buf) -} - -func (e *Encoder) write8(code byte, n uint64) error { - e.buf = e.buf[:9] - e.buf[0] = code - e.buf[1] = byte(n >> 56) - e.buf[2] = byte(n >> 48) - e.buf[3] = byte(n >> 40) - e.buf[4] = byte(n >> 32) - e.buf[5] = byte(n >> 24) - e.buf[6] = byte(n >> 16) - e.buf[7] = byte(n >> 8) - e.buf[8] = byte(n) - return e.write(e.buf) -} - -func encodeInt64Value(e *Encoder, v reflect.Value) error { - return e.EncodeInt64(v.Int()) -} - -func encodeUint64Value(e *Encoder, v reflect.Value) error { - return e.EncodeUint64(v.Uint()) -} - -func encodeFloat32Value(e *Encoder, v reflect.Value) error { - return e.EncodeFloat32(float32(v.Float())) -} - -func encodeFloat64Value(e *Encoder, v reflect.Value) error { - return e.EncodeFloat64(v.Float()) -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_slice.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_slice.go deleted file mode 100644 index 0a4e37d986f..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_slice.go +++ /dev/null @@ -1,120 +0,0 @@ -package msgpack - -import ( - "reflect" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -func encodeStringValue(e *Encoder, v reflect.Value) error { - return e.EncodeString(v.String()) -} - -func encodeByteSliceValue(e *Encoder, v reflect.Value) error { - return e.EncodeBytes(v.Bytes()) -} - -func encodeByteArrayValue(e *Encoder, v reflect.Value) error { - if err := e.EncodeBytesLen(v.Len()); err != nil { - return err - } - - if v.CanAddr() { - b := v.Slice(0, v.Len()).Bytes() - return e.write(b) - } - - b := make([]byte, v.Len()) - reflect.Copy(reflect.ValueOf(b), v) - return e.write(b) -} - -func (e *Encoder) EncodeBytesLen(l int) error { - if l < 256 { - return e.write1(codes.Bin8, uint64(l)) - } - if l < 65536 { - return e.write2(codes.Bin16, uint64(l)) - } - return e.write4(codes.Bin32, uint32(l)) -} - -func (e *Encoder) encodeStrLen(l int) error { - if l < 32 { - return e.w.WriteByte(codes.FixedStrLow | uint8(l)) - } - if l < 256 { - return e.write1(codes.Str8, uint64(l)) - } - if l < 65536 { - return e.write2(codes.Str16, uint64(l)) - } - return e.write4(codes.Str32, uint32(l)) -} - -func (e *Encoder) EncodeString(v string) error { - if err := e.encodeStrLen(len(v)); err != nil { - return err - } - return e.writeString(v) -} - -func (e *Encoder) EncodeBytes(v []byte) error { - if v == nil { - return e.EncodeNil() - } - if err := e.EncodeBytesLen(len(v)); err != nil { - return err - } - return e.write(v) -} - -func (e *Encoder) EncodeArrayLen(l int) error { - if l < 16 { - return e.w.WriteByte(codes.FixedArrayLow | byte(l)) - } - if l < 65536 { - return e.write2(codes.Array16, uint64(l)) - } - return e.write4(codes.Array32, uint32(l)) -} - -// Deprecated. Use EncodeArrayLen instead. -func (e *Encoder) EncodeSliceLen(l int) error { - return e.EncodeArrayLen(l) -} - -func (e *Encoder) encodeStringSlice(s []string) error { - if s == nil { - return e.EncodeNil() - } - if err := e.EncodeArrayLen(len(s)); err != nil { - return err - } - for _, v := range s { - if err := e.EncodeString(v); err != nil { - return err - } - } - return nil -} - -func encodeSliceValue(e *Encoder, v reflect.Value) error { - if v.IsNil() { - return e.EncodeNil() - } - return encodeArrayValue(e, v) -} - -func encodeArrayValue(e *Encoder, v reflect.Value) error { - l := v.Len() - if err := e.EncodeSliceLen(l); err != nil { - return err - } - for i := 0; i < l; i++ { - if err := e.EncodeValue(v.Index(i)); err != nil { - return err - } - } - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_value.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_value.go deleted file mode 100644 index 2f5a3509a85..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/encode_value.go +++ /dev/null @@ -1,167 +0,0 @@ -package msgpack - -import ( - "fmt" - "reflect" -) - -var valueEncoders []encoderFunc - -func init() { - valueEncoders = []encoderFunc{ - reflect.Bool: encodeBoolValue, - reflect.Int: encodeInt64Value, - reflect.Int8: encodeInt64Value, - reflect.Int16: encodeInt64Value, - reflect.Int32: encodeInt64Value, - reflect.Int64: encodeInt64Value, - reflect.Uint: encodeUint64Value, - reflect.Uint8: encodeUint64Value, - reflect.Uint16: encodeUint64Value, - reflect.Uint32: encodeUint64Value, - reflect.Uint64: encodeUint64Value, - reflect.Float32: encodeFloat32Value, - reflect.Float64: encodeFloat64Value, - reflect.Complex64: encodeUnsupportedValue, - reflect.Complex128: encodeUnsupportedValue, - reflect.Array: encodeArrayValue, - reflect.Chan: encodeUnsupportedValue, - reflect.Func: encodeUnsupportedValue, - reflect.Interface: encodeInterfaceValue, - reflect.Map: encodeMapValue, - reflect.Ptr: encodeUnsupportedValue, - reflect.Slice: encodeSliceValue, - reflect.String: encodeStringValue, - reflect.Struct: encodeStructValue, - reflect.UnsafePointer: encodeUnsupportedValue, - } -} - -func getEncoder(typ reflect.Type) encoderFunc { - if encoder, ok := typEncMap[typ]; ok { - return encoder - } - - if typ.Implements(customEncoderType) { - return encodeCustomValue - } - if typ.Implements(marshalerType) { - return marshalValue - } - - kind := typ.Kind() - - // Addressable struct field value. - if kind != reflect.Ptr { - ptr := reflect.PtrTo(typ) - if ptr.Implements(customEncoderType) { - return encodeCustomValuePtr - } - if ptr.Implements(marshalerType) { - return marshalValuePtr - } - } - - if typ == errorType { - return encodeErrorValue - } - - switch kind { - case reflect.Ptr: - return ptrEncoderFunc(typ) - case reflect.Slice: - if typ.Elem().Kind() == reflect.Uint8 { - return encodeByteSliceValue - } - case reflect.Array: - if typ.Elem().Kind() == reflect.Uint8 { - return encodeByteArrayValue - } - case reflect.Map: - if typ.Key() == stringType { - switch typ.Elem() { - case stringType: - return encodeMapStringStringValue - case interfaceType: - return encodeMapStringInterfaceValue - } - } - } - return valueEncoders[kind] -} - -func ptrEncoderFunc(typ reflect.Type) encoderFunc { - encoder := getEncoder(typ.Elem()) - return func(e *Encoder, v reflect.Value) error { - if v.IsNil() { - return e.EncodeNil() - } - return encoder(e, v.Elem()) - } -} - -func encodeCustomValuePtr(e *Encoder, v reflect.Value) error { - if !v.CanAddr() { - return fmt.Errorf("msgpack: Encode(non-addressable %T)", v.Interface()) - } - encoder := v.Addr().Interface().(CustomEncoder) - return encoder.EncodeMsgpack(e) -} - -func encodeCustomValue(e *Encoder, v reflect.Value) error { - switch v.Kind() { - case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: - if v.IsNil() { - return e.EncodeNil() - } - } - - encoder := v.Interface().(CustomEncoder) - return encoder.EncodeMsgpack(e) -} - -func marshalValuePtr(e *Encoder, v reflect.Value) error { - if !v.CanAddr() { - return fmt.Errorf("msgpack: Encode(non-addressable %T)", v.Interface()) - } - return marshalValue(e, v.Addr()) -} - -func marshalValue(e *Encoder, v reflect.Value) error { - switch v.Kind() { - case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: - if v.IsNil() { - return e.EncodeNil() - } - } - - marshaler := v.Interface().(Marshaler) - b, err := marshaler.MarshalMsgpack() - if err != nil { - return err - } - _, err = e.w.Write(b) - return err -} - -func encodeBoolValue(e *Encoder, v reflect.Value) error { - return e.EncodeBool(v.Bool()) -} - -func encodeInterfaceValue(e *Encoder, v reflect.Value) error { - if v.IsNil() { - return e.EncodeNil() - } - return e.EncodeValue(v.Elem()) -} - -func encodeErrorValue(e *Encoder, v reflect.Value) error { - if v.IsNil() { - return e.EncodeNil() - } - return e.EncodeString(v.Interface().(error).Error()) -} - -func encodeUnsupportedValue(e *Encoder, v reflect.Value) error { - return fmt.Errorf("msgpack: Encode(unsupported %s)", v.Type()) -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/ext.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/ext.go deleted file mode 100644 index 37ae53dd303..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/ext.go +++ /dev/null @@ -1,200 +0,0 @@ -package msgpack - -import ( - "bytes" - "fmt" - "reflect" - "sync" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -var extTypes []reflect.Type - -var bufferPool = &sync.Pool{ - New: func() interface{} { - return new(bytes.Buffer) - }, -} - -// RegisterExt records a type, identified by a value for that type, -// under the provided id. That id will identify the concrete type of a value -// sent or received as an interface variable. Only types that will be -// transferred as implementations of interface values need to be registered. -// Expecting to be used only during initialization, it panics if the mapping -// between types and ids is not a bijection. -func RegisterExt(id int8, value interface{}) { - if diff := int(id) - len(extTypes) + 1; diff > 0 { - extTypes = append(extTypes, make([]reflect.Type, diff)...) - } - - if extTypes[id] != nil { - panic(fmt.Errorf("msgpack: ext with id=%d is already registered", id)) - } - - typ := reflect.TypeOf(value) - if typ.Kind() == reflect.Ptr { - typ = typ.Elem() - } - ptr := reflect.PtrTo(typ) - - extTypes[id] = typ - decoder := getDecoder(typ) - Register(ptr, makeExtEncoder(id, getEncoder(ptr)), decoder) - Register(typ, makeExtEncoder(id, getEncoder(typ)), decoder) -} - -func makeExtEncoder(id int8, enc encoderFunc) encoderFunc { - return func(e *Encoder, v reflect.Value) error { - buf := bufferPool.Get().(*bytes.Buffer) - defer bufferPool.Put(buf) - buf.Reset() - - oldw := e.w - e.w = buf - err := enc(e, v) - e.w = oldw - - if err != nil { - return err - } - - if err := e.encodeExtLen(buf.Len()); err != nil { - return err - } - if err := e.w.WriteByte(byte(id)); err != nil { - return err - } - return e.write(buf.Bytes()) - } -} - -func (e *Encoder) encodeExtLen(l int) error { - switch l { - case 1: - return e.w.WriteByte(codes.FixExt1) - case 2: - return e.w.WriteByte(codes.FixExt2) - case 4: - return e.w.WriteByte(codes.FixExt4) - case 8: - return e.w.WriteByte(codes.FixExt8) - case 16: - return e.w.WriteByte(codes.FixExt16) - } - if l < 256 { - return e.write1(codes.Ext8, uint64(l)) - } - if l < 65536 { - return e.write2(codes.Ext16, uint64(l)) - } - return e.write4(codes.Ext32, uint32(l)) -} - -func (d *Decoder) decodeExtLen() (int, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return d.parseExtLen(c) -} - -func (d *Decoder) parseExtLen(c byte) (int, error) { - switch c { - case codes.FixExt1: - return 1, nil - case codes.FixExt2: - return 2, nil - case codes.FixExt4: - return 4, nil - case codes.FixExt8: - return 8, nil - case codes.FixExt16: - return 16, nil - case codes.Ext8: - n, err := d.uint8() - return int(n), err - case codes.Ext16: - n, err := d.uint16() - return int(n), err - case codes.Ext32: - n, err := d.uint32() - return int(n), err - default: - return 0, fmt.Errorf("msgpack: invalid code %x decoding ext length", c) - } -} - -func (d *Decoder) decodeExt() (interface{}, error) { - c, err := d.readByte() - if err != nil { - return 0, err - } - return d.ext(c) -} - -func (d *Decoder) ext(c byte) (interface{}, error) { - extLen, err := d.parseExtLen(c) - if err != nil { - return nil, err - } - // Save for later use. - d.extLen = extLen - - extId, err := d.readByte() - if err != nil { - return nil, err - } - - if int(extId) >= len(extTypes) { - return nil, fmt.Errorf("msgpack: unregistered ext id=%d", extId) - } - - typ := extTypes[extId] - if typ == nil { - return nil, fmt.Errorf("msgpack: unregistered ext id=%d", extId) - } - - v := reflect.New(typ).Elem() - if err := d.DecodeValue(v); err != nil { - return nil, err - } - - return v.Interface(), nil -} - -func (d *Decoder) skipExt(c byte) error { - n, err := d.parseExtLen(c) - if err != nil { - return err - } - return d.skipN(n) -} - -func (d *Decoder) skipExtHeader(c byte) error { - // Read ext type. - _, err := d.readByte() - if err != nil { - return err - } - // Read ext body len. - for i := 0; i < extHeaderLen(c); i++ { - _, err := d.readByte() - if err != nil { - return err - } - } - return nil -} - -func extHeaderLen(c byte) int { - switch c { - case codes.Ext8: - return 1 - case codes.Ext16: - return 2 - case codes.Ext32: - return 4 - } - return 0 -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/msgpack.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/msgpack.go deleted file mode 100644 index dbb53161a2c..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/msgpack.go +++ /dev/null @@ -1,19 +0,0 @@ -package msgpack // import "gopkg.in/vmihailenco/msgpack.v2" - -// Deprecated. Use CustomEncoder. -type Marshaler interface { - MarshalMsgpack() ([]byte, error) -} - -// Deprecated. Use CustomDecoder. -type Unmarshaler interface { - UnmarshalMsgpack([]byte) error -} - -type CustomEncoder interface { - EncodeMsgpack(*Encoder) error -} - -type CustomDecoder interface { - DecodeMsgpack(*Decoder) error -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/tags.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/tags.go deleted file mode 100644 index 7377f115944..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/tags.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package msgpack - -import ( - "strings" -) - -// tagOptions is the string following a comma in a struct field's "json" -// tag, or the empty string. It does not include the leading comma. -type tagOptions string - -// parseTag splits a struct field's json tag into its name and -// comma-separated options. -func parseTag(tag string) (string, tagOptions) { - if idx := strings.Index(tag, ","); idx != -1 { - return tag[:idx], tagOptions(tag[idx+1:]) - } - return tag, tagOptions("") -} - -// Contains reports whether a comma-separated list of options -// contains a particular substr flag. substr must be surrounded by a -// string boundary or commas. -func (o tagOptions) Contains(optionName string) bool { - if len(o) == 0 { - return false - } - s := string(o) - for s != "" { - var next string - i := strings.IndexRune(s, ',') - if i >= 0 { - s, next = s[:i], s[i+1:] - } - if s == optionName { - return true - } - s = next - } - return false -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/time.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/time.go deleted file mode 100644 index 8728894e6af..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/time.go +++ /dev/null @@ -1,59 +0,0 @@ -package msgpack - -import ( - "fmt" - "reflect" - "time" - - "gopkg.in/vmihailenco/msgpack.v2/codes" -) - -var timeType = reflect.TypeOf((*time.Time)(nil)).Elem() - -func init() { - Register(timeType, encodeTimeValue, decodeTimeValue) -} - -func (e *Encoder) EncodeTime(tm time.Time) error { - if err := e.w.WriteByte(codes.FixedArrayLow | 2); err != nil { - return err - } - if err := e.EncodeInt64(tm.Unix()); err != nil { - return err - } - return e.EncodeInt(tm.Nanosecond()) -} - -func (d *Decoder) DecodeTime() (time.Time, error) { - b, err := d.readByte() - if err != nil { - return time.Time{}, err - } - if b != 0x92 { - return time.Time{}, fmt.Errorf("msgpack: invalid code %x decoding time", b) - } - - sec, err := d.DecodeInt64() - if err != nil { - return time.Time{}, err - } - nsec, err := d.DecodeInt64() - if err != nil { - return time.Time{}, err - } - return time.Unix(sec, nsec), nil -} - -func encodeTimeValue(e *Encoder, v reflect.Value) error { - tm := v.Interface().(time.Time) - return e.EncodeTime(tm) -} - -func decodeTimeValue(d *Decoder, v reflect.Value) error { - tm, err := d.DecodeTime() - if err != nil { - return err - } - v.Set(reflect.ValueOf(tm)) - return nil -} diff --git a/vendor/gopkg.in/vmihailenco/msgpack.v2/types.go b/vendor/gopkg.in/vmihailenco/msgpack.v2/types.go deleted file mode 100644 index f1770b8c5ba..00000000000 --- a/vendor/gopkg.in/vmihailenco/msgpack.v2/types.go +++ /dev/null @@ -1,214 +0,0 @@ -package msgpack - -import ( - "reflect" - "sync" -) - -var errorType = reflect.TypeOf((*error)(nil)).Elem() - -var customEncoderType = reflect.TypeOf((*CustomEncoder)(nil)).Elem() -var customDecoderType = reflect.TypeOf((*CustomDecoder)(nil)).Elem() - -var marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem() -var unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem() - -type encoderFunc func(*Encoder, reflect.Value) error -type decoderFunc func(*Decoder, reflect.Value) error - -var typEncMap = make(map[reflect.Type]encoderFunc) -var typDecMap = make(map[reflect.Type]decoderFunc) - -// Register registers encoder and decoder functions for a type. -// In most cases you should prefer implementing CustomEncoder and -// CustomDecoder interfaces. -func Register(typ reflect.Type, enc encoderFunc, dec decoderFunc) { - if enc != nil { - typEncMap[typ] = enc - } - if dec != nil { - typDecMap[typ] = dec - } -} - -//------------------------------------------------------------------------------ - -var structs = newStructCache() - -type structCache struct { - l sync.RWMutex - m map[reflect.Type]*fields -} - -func newStructCache() *structCache { - return &structCache{ - m: make(map[reflect.Type]*fields), - } -} - -func (m *structCache) Fields(typ reflect.Type) *fields { - m.l.RLock() - fs, ok := m.m[typ] - m.l.RUnlock() - if !ok { - m.l.Lock() - fs, ok = m.m[typ] - if !ok { - fs = getFields(typ) - m.m[typ] = fs - } - m.l.Unlock() - } - - return fs -} - -//------------------------------------------------------------------------------ - -type field struct { - name string - index []int - omitEmpty bool - - encoder encoderFunc - decoder decoderFunc -} - -func (f *field) value(strct reflect.Value) reflect.Value { - return strct.FieldByIndex(f.index) -} - -func (f *field) Omit(strct reflect.Value) bool { - return f.omitEmpty && isEmptyValue(f.value(strct)) -} - -func (f *field) EncodeValue(e *Encoder, strct reflect.Value) error { - return f.encoder(e, f.value(strct)) -} - -func (f *field) DecodeValue(d *Decoder, strct reflect.Value) error { - return f.decoder(d, f.value(strct)) -} - -//------------------------------------------------------------------------------ - -type fields struct { - List []*field - Table map[string]*field - - asArray bool - omitEmpty bool -} - -func newFields(numField int) *fields { - return &fields{ - List: make([]*field, 0, numField), - Table: make(map[string]*field, numField), - } -} - -func (fs *fields) Len() int { - return len(fs.List) -} - -func (fs *fields) Add(field *field) { - fs.List = append(fs.List, field) - fs.Table[field.name] = field - if field.omitEmpty { - fs.omitEmpty = field.omitEmpty - } -} - -func (fs *fields) OmitEmpty(strct reflect.Value) []*field { - if !fs.omitEmpty { - return fs.List - } - - fields := make([]*field, 0, fs.Len()) - for _, f := range fs.List { - if !f.Omit(strct) { - fields = append(fields, f) - } - } - return fields -} - -func getFields(typ reflect.Type) *fields { - numField := typ.NumField() - fs := newFields(numField) - - var omitEmpty bool - for i := 0; i < numField; i++ { - f := typ.Field(i) - - name, opt := parseTag(f.Tag.Get("msgpack")) - if name == "-" { - continue - } - - if f.Name == "_msgpack" { - if opt.Contains("asArray") { - fs.asArray = true - } - if opt.Contains("omitempty") { - omitEmpty = true - } - } - - if f.PkgPath != "" && !f.Anonymous { - continue - } - - if opt.Contains("inline") { - inlineFields(fs, f) - continue - } - - if name == "" { - name = f.Name - } - field := field{ - name: name, - index: f.Index, - omitEmpty: omitEmpty || opt.Contains("omitempty"), - encoder: getEncoder(f.Type), - decoder: getDecoder(f.Type), - } - fs.Add(&field) - } - return fs -} - -func inlineFields(fs *fields, f reflect.StructField) { - typ := f.Type - if typ.Kind() == reflect.Ptr { - typ = typ.Elem() - } - inlinedFields := getFields(typ).List - for _, field := range inlinedFields { - if _, ok := fs.Table[field.name]; ok { - // Don't overwrite shadowed fields. - continue - } - field.index = append(f.Index, field.index...) - fs.Add(field) - } -} - -func isEmptyValue(v reflect.Value) bool { - switch v.Kind() { - case reflect.Array, reflect.Map, reflect.Slice, reflect.String: - return v.Len() == 0 - case reflect.Bool: - return !v.Bool() - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return v.Int() == 0 - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return v.Uint() == 0 - case reflect.Float32, reflect.Float64: - return v.Float() == 0 - case reflect.Interface, reflect.Ptr: - return v.IsNil() - } - return false -} diff --git a/vendor/vendor.json b/vendor/vendor.json index 0b304383255..a18fd163417 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -6751,18 +6751,6 @@ "revision": "3f83fa5005286a7fe593b055f0d7771a7dce4655", "revisionTime": "2016-08-18T02:01:20Z" }, - { - "checksumSHA1": "9zWLKf1I9P/EOJFQwdlf0oWBWdU=", - "path": "gopkg.in/vmihailenco/msgpack.v2", - "revision": "f4f8982de4ef0de18be76456617cc3f5d8d8141e", - "revisionTime": "2017-05-02T10:41:14Z" - }, - { - "checksumSHA1": "KqVHe5SB85yaDcseNq2CogozjRk=", - "path": "gopkg.in/vmihailenco/msgpack.v2/codes", - "revision": "f4f8982de4ef0de18be76456617cc3f5d8d8141e", - "revisionTime": "2017-05-02T10:41:14Z" - }, { "checksumSHA1": "ZSWoOPUNRr5+3dhkLK3C4cZAQPk=", "path": "gopkg.in/yaml.v2",