github.com/night-codes/go-json@v0.9.15/internal/decoder/invalid.go (about)

     1  package decoder
     2  
     3  import (
     4  	"reflect"
     5  	"unsafe"
     6  
     7  	"github.com/night-codes/go-json/internal/errors"
     8  	"github.com/night-codes/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  }