MCPcopy Index your code
hub / github.com/tinylib/msgp / ReadStringAsBytes

Method ReadStringAsBytes

msgp/read.go:1155–1204  ·  view source on GitHub ↗

ReadStringAsBytes reads a MessagePack 'str' (utf-8) string and returns its value as bytes. It may use 'scratch' for storage if it is non-nil.

(scratch []byte)

Source from the content-addressed store, hash-verified

1153// and returns its value as bytes. It may use 'scratch' for storage
1154// if it is non-nil.
1155func (m *Reader) ReadStringAsBytes(scratch []byte) (b []byte, err error) {
1156 var p []byte
1157 lead, err := m.R.PeekByte()
1158 if err != nil {
1159 return
1160 }
1161 var read int64
1162
1163 if isfixstr(lead) {
1164 read = int64(rfixstr(lead))
1165 m.R.Skip(1)
1166 goto fill
1167 }
1168
1169 switch lead {
1170 case mstr8:
1171 p, err = m.R.Next(2)
1172 if err != nil {
1173 return
1174 }
1175 read = int64(p[1])
1176 case mstr16:
1177 p, err = m.R.Next(3)
1178 if err != nil {
1179 return
1180 }
1181 read = int64(big.Uint16(p[1:]))
1182 case mstr32:
1183 p, err = m.R.Next(5)
1184 if err != nil {
1185 return
1186 }
1187 read = int64(big.Uint32(p[1:]))
1188 default:
1189 err = badPrefix(StrType, lead)
1190 return
1191 }
1192fill:
1193 if uint64(read) > m.GetMaxStringLength() {
1194 err = ErrLimitExceeded
1195 return
1196 }
1197 if int64(cap(scratch)) < read {
1198 b = make([]byte, read)
1199 } else {
1200 b = scratch[0:read]
1201 }
1202 _, err = m.R.ReadFull(b)
1203 return
1204}
1205
1206// ReadStringHeader reads a string header
1207// off of the wire. The user is then responsible

Callers 4

benchStringAsBytesFunction · 0.95
FuzzReaderFunction · 0.95
ReadMapKeyMethod · 0.95

Calls 6

GetMaxStringLengthMethod · 0.95
isfixstrFunction · 0.85
rfixstrFunction · 0.85
badPrefixFunction · 0.85
SkipMethod · 0.80
ReadFullMethod · 0.80

Tested by 2

benchStringAsBytesFunction · 0.76
FuzzReaderFunction · 0.76