invalid.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. }
  40. func (d *invalidDecoder) DecodePath(ctx *RuntimeContext, cursor, depth int64) ([][]byte, int64, error) {
  41. return nil, 0, &errors.UnmarshalTypeError{
  42. Value: "object",
  43. Type: runtime.RType2Type(d.typ),
  44. Offset: cursor,
  45. Struct: d.structName,
  46. Field: d.fieldName,
  47. }
  48. }