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

Method decodeMapStringInterface

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

Source from the content-addressed store, hash-verified

725}
726
727func (d decoder) decodeMapStringInterface(b []byte, p unsafe.Pointer) ([]byte, error) {
728 if hasNullPrefix(b) {
729 *(*unsafe.Pointer)(p) = nil
730 return b[4:], nil
731 }
732
733 if len(b) < 2 || b[0] != '{' {
734 return d.inputError(b, mapStringInterfaceType)
735 }
736
737 i := 0
738 m := *(*map[string]any)(p)
739
740 if m == nil {
741 m = make(map[string]any, 64)
742 }
743
744 var (
745 input = b
746 key string
747 val any
748 err error
749 )
750
751 b = b[1:]
752 for {
753 key = ""
754 val = nil
755
756 b = skipSpaces(b)
757
758 if len(b) != 0 && b[0] == '}' {
759 *(*unsafe.Pointer)(p) = *(*unsafe.Pointer)(unsafe.Pointer(&m))
760 return b[1:], nil
761 }
762
763 if i != 0 {
764 if len(b) == 0 {
765 return b, syntaxError(b, "unexpected end of JSON input after object field value")
766 }
767 if b[0] != ',' {
768 return b, syntaxError(b, "expected ',' after object field value but found '%c'", b[0])
769 }
770 b = skipSpaces(b[1:])
771 }
772
773 if hasNullPrefix(b) {
774 return b, syntaxError(b, "cannot decode object key string from 'null' value")
775 }
776
777 b, err = d.decodeString(b, unsafe.Pointer(&key))
778 if err != nil {
779 return objectKeyError(b, err)
780 }
781 b = skipSpaces(b)
782
783 if len(b) == 0 {
784 return b, syntaxError(b, "unexpected end of JSON input after object field key")

Callers 1

decodeInterfaceMethod · 0.95

Calls 10

inputErrorMethod · 0.95
decodeStringMethod · 0.95
decodeInterfaceMethod · 0.95
parseValueMethod · 0.95
prependFieldMethod · 0.95
hasNullPrefixFunction · 0.85
skipSpacesFunction · 0.85
syntaxErrorFunction · 0.85
objectKeyErrorFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected