github.com/3JoB/go-json@v0.10.4/internal/decoder/invalid.go (about) 1 package decoder 2 3 import ( 4 "unsafe" 5 6 "github.com/3JoB/go-reflect" 7 8 "github.com/3JoB/go-json/internal/errors" 9 "github.com/3JoB/go-json/internal/runtime" 10 ) 11 12 type invalidDecoder struct { 13 typ *runtime.Type 14 kind reflect.Kind 15 structName string 16 fieldName string 17 } 18 19 func newInvalidDecoder(typ *runtime.Type, structName, fieldName string) *invalidDecoder { 20 return &invalidDecoder{ 21 typ: typ, 22 kind: typ.Kind(), 23 structName: structName, 24 fieldName: fieldName, 25 } 26 } 27 28 func (d *invalidDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) error { 29 return &errors.UnmarshalTypeError{ 30 Value: "object", 31 Type: reflect.ToT(runtime.RType2Type(d.typ)), 32 Offset: s.totalOffset(), 33 Struct: d.structName, 34 Field: d.fieldName, 35 } 36 } 37 38 func (d *invalidDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer) (int64, error) { 39 return 0, &errors.UnmarshalTypeError{ 40 Value: "object", 41 Type: reflect.ToT(runtime.RType2Type(d.typ)), 42 Offset: cursor, 43 Struct: d.structName, 44 Field: d.fieldName, 45 } 46 } 47 48 func (d *invalidDecoder) DecodePath(ctx *RuntimeContext, cursor, depth int64) ([][]byte, int64, error) { 49 return nil, 0, &errors.UnmarshalTypeError{ 50 Value: "object", 51 Type: reflect.ToT(runtime.RType2Type(d.typ)), 52 Offset: cursor, 53 Struct: d.structName, 54 Field: d.fieldName, 55 } 56 }