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

Method decodeBytes

json/decode.go:402–436  ·  view source on GitHub ↗
(b []byte, p unsafe.Pointer)

Source from the content-addressed store, hash-verified

400}
401
402func (d decoder) decodeBytes(b []byte, p unsafe.Pointer) ([]byte, error) {
403 if hasNullPrefix(b) {
404 *(*[]byte)(p) = nil
405 return b[4:], nil
406 }
407
408 if len(b) < 2 {
409 return d.inputError(b, bytesType)
410 }
411
412 if b[0] != '"' {
413 // Go 1.7- behavior: bytes slices may be decoded from array of integers.
414 if len(b) > 0 && b[0] == '[' {
415 return d.decodeSlice(b, p, 1, bytesType, decoder.decodeUint8)
416 }
417 return d.inputError(b, bytesType)
418 }
419
420 // The input string contains escaped sequences, we need to parse it before
421 // decoding it to match the encoding/json package behvaior.
422 src, r, _, err := d.parseStringUnquote(b, nil)
423 if err != nil {
424 return d.inputError(b, bytesType)
425 }
426
427 dst := make([]byte, base64.StdEncoding.DecodedLen(len(src)))
428
429 n, err := base64.StdEncoding.Decode(dst, src)
430 if err != nil {
431 return r, err
432 }
433
434 *(*[]byte)(p) = dst[:n]
435 return r, nil
436}
437
438func (d decoder) decodeDuration(b []byte, p unsafe.Pointer) ([]byte, error) {
439 if hasNullPrefix(b) {

Callers 1

decodeSliceMethod · 0.95

Calls 5

inputErrorMethod · 0.95
decodeSliceMethod · 0.95
parseStringUnquoteMethod · 0.95
hasNullPrefixFunction · 0.85
DecodeMethod · 0.45

Tested by

no test coverage detected