invalid.go 1014 B

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