github.com/goccy/go-json@v0.10.3-0.20240509105655-5e2ae3f23c1d/internal/decoder/invalid.go (about)

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