package decoder
import (
"encoding"
"fmt"
"reflect"
"unsafe"
"github.com/goccy/go-json/internal/jsonstring"
"github.com/goccy/go-json/internal/runtime"
)
type unmarshalTextDecoder struct {
typ reflect .Type
}
func newUnmarshalTextDecoder(typ reflect .Type ) *unmarshalTextDecoder {
return &unmarshalTextDecoder {typ : typ }
}
var (
nullbytes = []byte (`null` )
)
func (d *unmarshalTextDecoder ) Decode (ctx *RuntimeContext , cursor , depth int64 , p unsafe .Pointer ) (int64 , error ) {
end , methodErr , err := d .decodeText (ctx , cursor , depth , p )
if methodErr != nil {
ctx .methodError (methodErr )
}
return end , err
}
func (d *unmarshalTextDecoder ) decodeText (ctx *RuntimeContext , cursor , depth int64 , p unsafe .Pointer ) (int64 , error , error ) {
buf := ctx .Buf
cursor = skipWhiteSpace (buf , cursor )
start := cursor
end , err := skipValue (buf , cursor , depth )
if err != nil {
return 0 , nil , err
}
src := buf [start :end ]
switch c := src [0 ]; {
case c == 'n' :
return end , nil , nil
case c != '"' :
end , err := ctx .textUnmarshalerKindError (start , depth , d .typ )
return end , nil , err
}
src = jsonstring .UnquoteValid (src )
src = src [:len (src ):len (src )]
v := *(*any )(unsafe .Pointer (&emptyInterface {
typ : runtime .TypePtr (d .typ ),
ptr : *(*unsafe .Pointer )(unsafe .Pointer (&p )),
}))
return end , v .(encoding .TextUnmarshaler ).UnmarshalText (src ), nil
}
type textKeyDecoder struct {
unmarshalTextDecoder
}
func (d *textKeyDecoder ) Decode (ctx *RuntimeContext , cursor , depth int64 , p unsafe .Pointer ) (int64 , error ) {
end , methodErr , err := d .decodeText (ctx , cursor , depth , p )
if methodErr != nil {
ctx .methodError (methodErr )
return end , errMapKeyType
}
return end , err
}
func (d *unmarshalTextDecoder ) DecodePath (ctx *RuntimeContext , cursor , depth int64 ) ([][]byte , int64 , error ) {
return nil , 0 , fmt .Errorf ("json: unmarshal text decoder does not support decode path" )
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .