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

Function AppendString

msgp/write_bytes.go:243–266  ·  view source on GitHub ↗

AppendString appends a string as a MessagePack 'str' to the slice

(b []byte, s string)

Source from the content-addressed store, hash-verified

241
242// AppendString appends a string as a MessagePack 'str' to the slice
243func AppendString(b []byte, s string) []byte {
244 sz := len(s)
245 var n int
246 var o []byte
247 switch {
248 case sz <= 31:
249 o, n = ensure(b, 1+sz)
250 o[n] = wfixstr(uint8(sz))
251 n++
252 case sz <= math.MaxUint8:
253 o, n = ensure(b, 2+sz)
254 prefixu8(o[n:], mstr8, uint8(sz))
255 n += 2
256 case sz <= math.MaxUint16:
257 o, n = ensure(b, 3+sz)
258 prefixu16(o[n:], mstr16, uint16(sz))
259 n += 3
260 default:
261 o, n = ensure(b, 5+sz)
262 prefixu32(o[n:], mstr32, uint32(sz))
263 n += 5
264 }
265 return o[:n+copy(o[n:], s)]
266}
267
268// AppendStringFromBytes appends a []byte
269// as a MessagePack 'str' to the slice 'b.'

Callers 15

MarshalMsgMethod · 0.92
MarshalMsgMethod · 0.92
gStructMethod · 0.92
fixedsizeExprFunction · 0.92
mapstructMethod · 0.92
structmapMethod · 0.92
mainFunction · 0.92
TestMapLimitEnforcementFunction · 0.92
TestSliceLimitsAppliedFunction · 0.92
TestNestedArrayLimitsFunction · 0.92

Calls 5

wfixstrFunction · 0.85
prefixu8Function · 0.85
prefixu16Function · 0.85
prefixu32Function · 0.85
ensureFunction · 0.70

Tested by 15

TestMapLimitEnforcementFunction · 0.74
TestSliceLimitsAppliedFunction · 0.74
TestNestedArrayLimitsFunction · 0.74
TestMapExceedsLimitFunction · 0.74
TestAllowNilZeroCopyFunction · 0.74
benchStringFunction · 0.68
benchStringAsBytesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…