| 1 |
package decoder |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"unsafe" |
| 6 |
|
| 7 |
"github.com/goccy/go-json/internal/errors" |
| 8 |
) |
| 9 |
|
| 10 |
type invalidDecoder struct { |
| 11 |
typ reflect.Type |
| 12 |
kind reflect.Kind |
| 13 |
structName string |
| 14 |
fieldName string |
| 15 |
} |
| 16 |
|
| 17 |
func newInvalidDecoder(typ reflect.Type, structName, fieldName string) *invalidDecoder { |
| 18 |
return &invalidDecoder{ |
| 19 |
typ: typ, |
| 20 |
kind: typ.Kind(), |
| 21 |
structName: structName, |
| 22 |
fieldName: fieldName, |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
// Decode skips the value, which no value of the type can be decoded from: it is a type error, as encoding/json |
| 27 |
// reports it, but null, which is ignored. |
| 28 |
func (d *invalidDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer) (int64, error) { |
| 29 |
buf := ctx.Buf |
| 30 |
cursor = skipWhiteSpace(buf, cursor) |
| 31 |
if buf[cursor] == 'n' { |
| 32 |
if err := validateNull(buf, cursor); err != nil { |
| 33 |
return 0, err |
| 34 |
} |
| 35 |
return cursor + 4, nil |
| 36 |
} |
| 37 |
return ctx.skipTypeError(cursor, depth, d.typ) |
| 38 |
} |
| 39 |
|
| 40 |
func (d *invalidDecoder) DecodePath(ctx *RuntimeContext, cursor, depth int64) ([][]byte, int64, error) { |
| 41 |
return nil, 0, &errors.UnmarshalTypeError{ |
| 42 |
Value: "object", |
| 43 |
Type: d.typ, |
| 44 |
Offset: cursor, |
| 45 |
Struct: d.structName, |
| 46 |
Field: d.fieldName, |
| 47 |
} |
| 48 |
} |