diff options
author | Luke Shumaker <lukeshu@datawire.io> | 2022-08-14 20:52:06 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@datawire.io> | 2022-08-16 00:05:24 -0600 |
commit | 54bbd1e59317a6e9658eb8098657078cc8e81979 (patch) | |
tree | 0d7033a0644945dedfe0fca158e0c40864f759f6 /decode_scan.go | |
parent | 2ae2ebe2a5ac712db6f9221cb1ad8cfa76aad180 (diff) |
wip: Reduce test differences [ci-skip]
- Handle UTF-16 surrogate pairs
- Handle cycles in values
- Handle cycles in types
- Better errors
- Handle case-folding of struct field names
- Allow []byteTypeWithMethods
- Fix struct field-order
- Fix handling of interfaces storing pointers
- Enforce a maximum decode depth
- Validate struct tags
Diffstat (limited to 'decode_scan.go')
-rw-r--r-- | decode_scan.go | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/decode_scan.go b/decode_scan.go index e75f1c5..3c41df6 100644 --- a/decode_scan.go +++ b/decode_scan.go @@ -6,29 +6,9 @@ package lowmemjson import ( "errors" - "fmt" "io" ) -type ReadError struct { - Err error - Offset int64 -} - -func (e *ReadError) Error() string { - return fmt.Sprintf("json: I/O error at input byte %v: %v", e.Offset, e.Err) -} -func (e *ReadError) Unwrap() error { return e.Err } - -type SyntaxError struct { - Err string - Offset int64 -} - -func (e *SyntaxError) Error() string { - return fmt.Sprintf("json: syntax error at input byte %v: %v", e.Offset, e.Err) -} - type runeTypeScanner interface { // The returned error is a *ReadError, a *SyntaxError, or nil. // An EOF condition is represented either as @@ -37,9 +17,9 @@ type runeTypeScanner interface { // // or // - // (char, size, RuneTypeError, &SyntaxError{Offset: offset: Err: io.ErrUnexepctedEOF}) + // (char, size, RuneTypeError, &DecodeSyntaxError{Offset: offset: Err: io.ErrUnexepctedEOF}) ReadRuneType() (rune, int, RuneType, error) - // The returned error is a *ReadError, a *SyntaxError, io.EOF, or nil. + // The returned error is a *DecodeReadError, a *DecodeSyntaxError, io.EOF, or nil. ReadRune() (rune, int, error) UnreadRune() error Reset() @@ -86,9 +66,9 @@ func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, RuneType, error) { case nil: sc.rType, err = sc.parser.HandleRune(sc.rRune) if err != nil { - sc.rErr = &SyntaxError{ + sc.rErr = &DecodeSyntaxError{ Offset: sc.offset, - Err: err.Error(), + Err: err, } } else { sc.rErr = nil @@ -96,16 +76,16 @@ func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, RuneType, error) { case io.EOF: sc.rType, err = sc.parser.HandleEOF() if err != nil { - sc.rErr = &SyntaxError{ + sc.rErr = &DecodeSyntaxError{ Offset: sc.offset, - Err: err.Error(), + Err: err, } } else { sc.rErr = nil } default: sc.rType = 0 - sc.rErr = &ReadError{ + sc.rErr = &DecodeReadError{ Offset: sc.offset, Err: err, } |