Parse behaves like Unmarshal but the caller can pass a set of flags to configure the parsing behavior.
(b []byte, x any, flags ParseFlags)
| 315 | // Parse behaves like Unmarshal but the caller can pass a set of flags to |
| 316 | // configure the parsing behavior. |
| 317 | func 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 |
| 347 | func Valid(data []byte) bool { |
searching dependent graphs…