MCPcopy
hub / github.com/tinylib/msgp / ReadBytes

Method ReadBytes

msgp/read.go:974–1014  ·  view source on GitHub ↗

ReadBytes reads a MessagePack 'bin' object from the reader and returns its value. It may use 'scratch' for storage if it is non-nil.

(scratch []byte)

Source from the content-addressed store, hash-verified

972// from the reader and returns its value. It may
973// use 'scratch' for storage if it is non-nil.
974func (m *Reader) ReadBytes(scratch []byte) (b []byte, err error) {
975 var p []byte
976 var lead byte
977 p, err = m.R.Peek(2)
978 if err != nil {
979 return
980 }
981 lead = p[0]
982 var read int64
983 switch lead {
984 case mbin8:
985 read = int64(p[1])
986 m.R.Skip(2)
987 case mbin16:
988 p, err = m.R.Next(3)
989 if err != nil {
990 return
991 }
992 read = int64(big.Uint16(p[1:]))
993 case mbin32:
994 p, err = m.R.Next(5)
995 if err != nil {
996 return
997 }
998 read = int64(big.Uint32(p[1:]))
999 default:
1000 err = badPrefix(BinType, lead)
1001 return
1002 }
1003 if int64(cap(scratch)) < read {
1004 if read > int64(m.GetMaxElements()) {
1005 err = ErrLimitExceeded
1006 return
1007 }
1008 b = make([]byte, read)
1009 } else {
1010 b = scratch[0:read]
1011 }
1012 _, err = m.R.ReadFull(b)
1013 return
1014}
1015
1016// ReadBytesLimit reads a MessagePack 'bin' object
1017// from the reader and returns its value. It may

Callers 10

TestReadBytesFunction · 0.95
benchBytesFunction · 0.95
FuzzReaderFunction · 0.95
ReadMapKeyMethod · 0.95
ReadIntfMethod · 0.95
ReadBinaryUnmarshalMethod · 0.95
ReadTextUnmarshalMethod · 0.95
rwBytesFunction · 0.80

Calls 4

GetMaxElementsMethod · 0.95
badPrefixFunction · 0.85
SkipMethod · 0.80
ReadFullMethod · 0.80

Tested by 5

TestReadBytesFunction · 0.76
benchBytesFunction · 0.76
FuzzReaderFunction · 0.76