MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / parseUsingFastParser

Function parseUsingFastParser

pkg/util/json/parser.go:20–54  ·  view source on GitHub ↗

parseUsingFastParser parses string as JSON using fast json parser.

(s string, cfg parseConfig)

Source from the content-addressed store, hash-verified

18
19// parseUsingFastParser parses string as JSON using fast json parser.
20func parseUsingFastParser(s string, cfg parseConfig) (JSON, error) {
21 input, err := unsafeGetBytes(s)
22 if err != nil {
23 return nil, err
24 }
25
26 p := fastJSONParser{
27 parseConfig: cfg,
28 decoder: tokenizer.MakeDecoder(input),
29 state: (*fastJSONParser).parseTopValue,
30 }
31 defer p.decoder.Release()
32
33 j, err := p.parse()
34 if err != nil {
35 if errors.Is(err, io.ErrUnexpectedEOF) && p.decoder.More() {
36 // JSON scanner returns nil token if it encounters an invalid input
37 // character. In such cases, decoder returns io.ErrUnexpectedEOF error.
38 // However, we know it's not an EOF because decoder has more data. So,
39 // produce a bit nicer error message.
40 return nil, jsonDecodeError(decodeErrorContext(errInvalidInputToken, s, p.decoder.Pos()))
41 }
42 return nil, jsonDecodeError(decodeErrorContext(err, s, p.decoder.Pos()))
43 }
44
45 if j == nil {
46 return nil, errors.AssertionFailedf("expected parsed JSON value, got nil")
47 }
48
49 if p.decoder.More() {
50 return nil, jsonDecodeError(decodeErrorContext(errTrailingCharacters, s, p.decoder.Pos()+1))
51 }
52
53 return j, nil
54}
55
56// fastJSONParser builds JSON given input string. This implementation uses low level
57// API provided by fork of github.com/pkg/json package to implement direct

Callers 1

parseJSONMethod · 0.85

Calls 8

parseMethod · 0.95
MakeDecoderFunction · 0.92
unsafeGetBytesFunction · 0.85
jsonDecodeErrorFunction · 0.85
decodeErrorContextFunction · 0.85
PosMethod · 0.65
ReleaseMethod · 0.45
MoreMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…