AppendStringFromBytes appends a []byte as a MessagePack 'str' to the slice 'b.'
(b []byte, str []byte)
| 268 | // AppendStringFromBytes appends a []byte |
| 269 | // as a MessagePack 'str' to the slice 'b.' |
| 270 | func AppendStringFromBytes(b []byte, str []byte) []byte { |
| 271 | sz := len(str) |
| 272 | var n int |
| 273 | var o []byte |
| 274 | switch { |
| 275 | case sz <= 31: |
| 276 | o, n = ensure(b, 1+sz) |
| 277 | o[n] = wfixstr(uint8(sz)) |
| 278 | n++ |
| 279 | case sz <= math.MaxUint8: |
| 280 | o, n = ensure(b, 2+sz) |
| 281 | prefixu8(o[n:], mstr8, uint8(sz)) |
| 282 | n += 2 |
| 283 | case sz <= math.MaxUint16: |
| 284 | o, n = ensure(b, 3+sz) |
| 285 | prefixu16(o[n:], mstr16, uint16(sz)) |
| 286 | n += 3 |
| 287 | default: |
| 288 | o, n = ensure(b, 5+sz) |
| 289 | prefixu32(o[n:], mstr32, uint32(sz)) |
| 290 | n += 5 |
| 291 | } |
| 292 | return o[:n+copy(o[n:], str)] |
| 293 | } |
| 294 | |
| 295 | // AppendComplex64 appends a complex64 to the slice as a MessagePack extension |
| 296 | func AppendComplex64(b []byte, c complex64) []byte { |