diff options
Diffstat (limited to 'vendor/github.com/tinylib/msgp')
-rw-r--r-- | vendor/github.com/tinylib/msgp/msgp/errors.go | 3 | ||||
-rw-r--r-- | vendor/github.com/tinylib/msgp/msgp/json.go | 4 | ||||
-rw-r--r-- | vendor/github.com/tinylib/msgp/msgp/read.go | 5 | ||||
-rw-r--r-- | vendor/github.com/tinylib/msgp/msgp/read_bytes.go | 40 | ||||
-rw-r--r-- | vendor/github.com/tinylib/msgp/msgp/unsafe.go | 17 | ||||
-rw-r--r-- | vendor/github.com/tinylib/msgp/msgp/write.go | 24 | ||||
-rw-r--r-- | vendor/github.com/tinylib/msgp/msgp/write_bytes.go | 20 |
7 files changed, 96 insertions, 17 deletions
diff --git a/vendor/github.com/tinylib/msgp/msgp/errors.go b/vendor/github.com/tinylib/msgp/msgp/errors.go index cc78a980..921e8553 100644 --- a/vendor/github.com/tinylib/msgp/msgp/errors.go +++ b/vendor/github.com/tinylib/msgp/msgp/errors.go @@ -123,6 +123,9 @@ func (e errWrapped) Resumable() bool { return resumableDefault } +// Unwrap returns the cause. +func (e errWrapped) Unwrap() error { return e.cause } + type errShort struct{} func (e errShort) Error() string { return "msgp: too few bytes left to read object" } diff --git a/vendor/github.com/tinylib/msgp/msgp/json.go b/vendor/github.com/tinylib/msgp/msgp/json.go index 77601e52..0e11e603 100644 --- a/vendor/github.com/tinylib/msgp/msgp/json.go +++ b/vendor/github.com/tinylib/msgp/msgp/json.go @@ -206,7 +206,7 @@ func rwFloat32(dst jsWriter, src *Reader) (int, error) { if err != nil { return 0, err } - src.scratch = strconv.AppendFloat(src.scratch[:0], float64(f), 'f', -1, 64) + src.scratch = strconv.AppendFloat(src.scratch[:0], float64(f), 'f', -1, 32) return dst.Write(src.scratch) } @@ -215,7 +215,7 @@ func rwFloat64(dst jsWriter, src *Reader) (int, error) { if err != nil { return 0, err } - src.scratch = strconv.AppendFloat(src.scratch[:0], f, 'f', -1, 32) + src.scratch = strconv.AppendFloat(src.scratch[:0], f, 'f', -1, 64) return dst.Write(src.scratch) } diff --git a/vendor/github.com/tinylib/msgp/msgp/read.go b/vendor/github.com/tinylib/msgp/msgp/read.go index aa668c57..fe2de9e0 100644 --- a/vendor/github.com/tinylib/msgp/msgp/read.go +++ b/vendor/github.com/tinylib/msgp/msgp/read.go @@ -126,6 +126,11 @@ func NewReaderSize(r io.Reader, sz int) *Reader { return &Reader{R: fwd.NewReaderSize(r, sz)} } +// NewReaderBuf returns a *Reader with a provided buffer. +func NewReaderBuf(r io.Reader, buf []byte) *Reader { + return &Reader{R: fwd.NewReaderBuf(r, buf)} +} + // Reader wraps an io.Reader and provides // methods to read MessagePack-encoded values // from it. Readers are buffered. diff --git a/vendor/github.com/tinylib/msgp/msgp/read_bytes.go b/vendor/github.com/tinylib/msgp/msgp/read_bytes.go index e4199757..f6674507 100644 --- a/vendor/github.com/tinylib/msgp/msgp/read_bytes.go +++ b/vendor/github.com/tinylib/msgp/msgp/read_bytes.go @@ -253,6 +253,46 @@ func ReadArrayHeaderBytes(b []byte) (sz uint32, o []byte, err error) { } } +// ReadBytesHeader reads the 'bin' header size +// off of 'b' and returns the size and remaining bytes. +// Possible errors: +// - ErrShortBytes (too few bytes) +// - TypeError{} (not a bin object) +func ReadBytesHeader(b []byte) (sz uint32, o []byte, err error) { + if len(b) < 1 { + return 0, nil, ErrShortBytes + } + switch b[0] { + case mbin8: + if len(b) < 2 { + err = ErrShortBytes + return + } + sz = uint32(b[1]) + o = b[2:] + return + case mbin16: + if len(b) < 3 { + err = ErrShortBytes + return + } + sz = uint32(big.Uint16(b[1:])) + o = b[3:] + return + case mbin32: + if len(b) < 5 { + err = ErrShortBytes + return + } + sz = big.Uint32(b[1:]) + o = b[5:] + return + default: + err = badPrefix(BinType, b[0]) + return + } +} + // ReadNilBytes tries to read a "nil" byte // off of 'b' and return the remaining bytes. // Possible errors: diff --git a/vendor/github.com/tinylib/msgp/msgp/unsafe.go b/vendor/github.com/tinylib/msgp/msgp/unsafe.go index 3978b6ff..d9fb3535 100644 --- a/vendor/github.com/tinylib/msgp/msgp/unsafe.go +++ b/vendor/github.com/tinylib/msgp/msgp/unsafe.go @@ -3,7 +3,6 @@ package msgp import ( - "reflect" "unsafe" ) @@ -24,18 +23,14 @@ const ( // THIS IS EVIL CODE. // YOU HAVE BEEN WARNED. func UnsafeString(b []byte) string { - sh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) - return *(*string)(unsafe.Pointer(&reflect.StringHeader{Data: sh.Data, Len: sh.Len})) + return *(*string)(unsafe.Pointer(&b)) } // UnsafeBytes returns the string as a byte slice -// THIS SHOULD ONLY BE USED BY THE CODE GENERATOR. -// THIS IS EVIL CODE. -// YOU HAVE BEEN WARNED. +// +// Deprecated: +// Since this code is no longer used by the code generator, +// UnsafeBytes(s) is precisely equivalent to []byte(s) func UnsafeBytes(s string) []byte { - return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ - Len: len(s), - Cap: len(s), - Data: (*(*reflect.StringHeader)(unsafe.Pointer(&s))).Data, - })) + return []byte(s) } diff --git a/vendor/github.com/tinylib/msgp/msgp/write.go b/vendor/github.com/tinylib/msgp/msgp/write.go index fb1947c5..407ec1f8 100644 --- a/vendor/github.com/tinylib/msgp/msgp/write.go +++ b/vendor/github.com/tinylib/msgp/msgp/write.go @@ -10,6 +10,11 @@ import ( "time" ) +const ( + // min buffer size for the writer + minWriterSize = 18 +) + // Sizer is an interface implemented // by types that can estimate their // size when MessagePack encoded. @@ -120,16 +125,27 @@ func NewWriter(w io.Writer) *Writer { // NewWriterSize returns a writer with a custom buffer size. func NewWriterSize(w io.Writer, sz int) *Writer { - // we must be able to require() 18 + // we must be able to require() 'minWriterSize' // contiguous bytes, so that is the // practical minimum buffer size - if sz < 18 { - sz = 18 + if sz < minWriterSize { + sz = minWriterSize } + buf := make([]byte, sz) + return NewWriterBuf(w, buf) +} +// NewWriterBuf returns a writer with a provided buffer. +// 'buf' is not used when the capacity is smaller than 18, +// custom buffer is allocated instead. +func NewWriterBuf(w io.Writer, buf []byte) *Writer { + if cap(buf) < minWriterSize { + buf = make([]byte, minWriterSize) + } + buf = buf[:cap(buf)] return &Writer{ w: w, - buf: make([]byte, sz), + buf: buf, } } diff --git a/vendor/github.com/tinylib/msgp/msgp/write_bytes.go b/vendor/github.com/tinylib/msgp/msgp/write_bytes.go index eaa03c46..93d6d764 100644 --- a/vendor/github.com/tinylib/msgp/msgp/write_bytes.go +++ b/vendor/github.com/tinylib/msgp/msgp/write_bytes.go @@ -193,6 +193,26 @@ func AppendBytes(b []byte, bts []byte) []byte { return o[:n+copy(o[n:], bts)] } +// AppendBytesHeader appends an 'bin' header with +// the given size to the slice. +func AppendBytesHeader(b []byte, sz uint32) []byte { + var o []byte + var n int + switch { + case sz <= math.MaxUint8: + o, n = ensure(b, 2) + prefixu8(o[n:], mbin8, uint8(sz)) + return o + case sz <= math.MaxUint16: + o, n = ensure(b, 3) + prefixu16(o[n:], mbin16, uint16(sz)) + return o + } + o, n = ensure(b, 5) + prefixu32(o[n:], mbin32, sz) + return o +} + // AppendBool appends a bool to the slice func AppendBool(b []byte, t bool) []byte { if t { |