MCPcopy Index your code
hub / github.com/segmentio/encoding / encodeBytes

Method encodeBytes

json/encode.go:241–263  ·  view source on GitHub ↗
(b []byte, p unsafe.Pointer)

Source from the content-addressed store, hash-verified

239}
240
241func (e encoder) encodeBytes(b []byte, p unsafe.Pointer) ([]byte, error) {
242 v := *(*[]byte)(p)
243 if v == nil {
244 return append(b, "null"...), nil
245 }
246
247 n := base64.StdEncoding.EncodedLen(len(v)) + 2
248
249 if avail := cap(b) - len(b); avail < n {
250 newB := make([]byte, cap(b)+(n-avail))
251 copy(newB, b)
252 b = newB[:len(b)]
253 }
254
255 i := len(b)
256 j := len(b) + n
257
258 b = b[:j]
259 b[i] = '"'
260 base64.StdEncoding.Encode(b[i+1:j-1], v)
261 b[j-1] = '"'
262 return b, nil
263}
264
265func (e encoder) encodeDuration(b []byte, p unsafe.Pointer) ([]byte, error) {
266 b = append(b, '"')

Callers

nothing calls this directly

Calls 1

EncodeMethod · 0.45

Tested by

no test coverage detected