package decoder
import (
"bytes"
"encoding/json"
stdjsontext "encoding/json/jsontext"
stdjson "encoding/json/v2"
"reflect"
"sync"
"github.com/goccy/go-json/internal/errors"
)
var stdUnmarshalerFromType = reflect .TypeFor [stdjson .UnmarshalerFrom ]()
type stdFromDecoder struct {
r bytes .Reader
dec *stdjsontext .Decoder
}
var stdFromDecoders = sync .Pool {New : func () any {
d := new (stdFromDecoder )
d .dec = stdjsontext .NewDecoder (&d .r )
return d
}}
var (
stdFromOptions = json .DefaultOptionsV1 ()
stdFromRejectOptions = stdjson .JoinOptions (stdFromOptions , stdjson .RejectUnknownMembers (true ))
)
func stdUnmarshalFrom(v any , value []byte , flags OptionFlags ) (bool , error ) {
d := stdFromDecoders .Get ().(*stdFromDecoder )
defer stdFromDecoders .Put (d )
d .r .Reset (value )
opts := stdFromOptions
if flags &DisallowUnknownFieldsOption != 0 {
opts = stdFromRejectOptions
}
d .dec .Reset (&d .r , opts )
err := v .(stdjson .UnmarshalerFrom ).UnmarshalJSONFrom (d .dec )
_ , n := d .dec .StackIndex (0 )
declined , err := errors .MethodCallResult (err , d .dec .StackDepth (), n )
d .r .Reset (nil )
return declined , err
}
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 .