AppendString appends a string as a MessagePack 'str' to the slice
(b []byte, s string)
| 241 | |
| 242 | // AppendString appends a string as a MessagePack 'str' to the slice |
| 243 | func 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.' |
searching dependent graphs…