MCPcopy Create free account
hub / github.com/segmentio/encoding / Parse

Function Parse

json/json.go:317–344  ·  view source on GitHub ↗

Parse behaves like Unmarshal but the caller can pass a set of flags to configure the parsing behavior.

(b []byte, x any, flags ParseFlags)

Source from the content-addressed store, hash-verified

315// Parse behaves like Unmarshal but the caller can pass a set of flags to
316// configure the parsing behavior.
317func Parse(b []byte, x any, flags ParseFlags) ([]byte, error) {
318 t := reflect.TypeOf(x)
319 p := (*iface)(unsafe.Pointer(&x)).ptr
320
321 d := decoder{flags: flags | internalParseFlags(b)}
322
323 b = skipSpaces(b)
324
325 if t == nil || p == nil || t.Kind() != reflect.Ptr {
326 _, r, _, err := d.parseValue(b)
327 r = skipSpaces(r)
328 if err != nil {
329 return r, err
330 }
331 return r, &InvalidUnmarshalError{Type: t}
332 }
333 t = t.Elem()
334
335 cache := cacheLoad()
336 c, found := cache[typeid(t)]
337
338 if !found {
339 c = constructCachedCodec(t, cache)
340 }
341
342 r, err := c.decode(d, b, p)
343 return skipSpaces(r), err
344}
345
346// Valid is documented at https://golang.org/pkg/encoding/json/#Valid
347func Valid(data []byte) bool {

Callers 7

TestMainFunction · 0.70
TestParse_numericFunction · 0.70
decodeInterfaceMethod · 0.70
UnmarshalFunction · 0.70
DecodeMethod · 0.70

Calls 9

parseValueMethod · 0.95
internalParseFlagsFunction · 0.85
skipSpacesFunction · 0.85
cacheLoadFunction · 0.85
typeidFunction · 0.85
constructCachedCodecFunction · 0.85
decodeMethod · 0.80
KindMethod · 0.65
ElemMethod · 0.65

Tested by 3

TestMainFunction · 0.56
TestParse_numericFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…