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

Method decodeSlice

json/decode.go:570–645  ·  view source on GitHub ↗
(b []byte, p unsafe.Pointer, size uintptr, t reflect.Type, decode decodeFunc)

Source from the content-addressed store, hash-verified

568var empty struct{}
569
570func (d decoder) decodeSlice(b []byte, p unsafe.Pointer, size uintptr, t reflect.Type, decode decodeFunc) ([]byte, error) {
571 if hasNullPrefix(b) {
572 *(*slice)(p) = slice{}
573 return b[4:], nil
574 }
575
576 if len(b) < 2 {
577 return d.inputError(b, t)
578 }
579
580 if b[0] != '[' {
581 // Go 1.7- behavior: fallback to decoding as a []byte if the element
582 // type is byte; allow conversions from JSON strings even tho the
583 // underlying type implemented unmarshaler interfaces.
584 if t.Elem().Kind() == reflect.Uint8 {
585 return d.decodeBytes(b, p)
586 }
587 return d.inputError(b, t)
588 }
589
590 input := b
591 b = b[1:]
592
593 s := (*slice)(p)
594 s.len = 0
595
596 var err error
597 for {
598 b = skipSpaces(b)
599
600 if len(b) != 0 && b[0] == ']' {
601 if s.data == nil {
602 s.data = unsafe.Pointer(&empty)
603 }
604 return b[1:], nil
605 }
606
607 if s.len != 0 {
608 if len(b) == 0 {
609 return b, syntaxError(b, "unexpected EOF after array element")
610 }
611 if b[0] != ',' {
612 return b, syntaxError(b, "expected ',' after array element but found '%c'", b[0])
613 }
614 b = skipSpaces(b[1:])
615 }
616
617 if s.len == s.cap {
618 c := s.cap
619
620 if c == 0 {
621 c = 10
622 } else {
623 c *= 2
624 }
625
626 *s = extendSlice(t, s, c)
627 }

Callers 4

decodeBytesMethod · 0.95
decodeInterfaceMethod · 0.95
constructSliceDecodeFuncFunction · 0.80

Calls 11

inputErrorMethod · 0.95
decodeBytesMethod · 0.95
parseValueMethod · 0.95
prependFieldMethod · 0.95
hasNullPrefixFunction · 0.85
skipSpacesFunction · 0.85
syntaxErrorFunction · 0.85
extendSliceFunction · 0.70
KindMethod · 0.65
ElemMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected