badjson: Add context marshaler/unmarshaler

This commit is contained in:
世界 2024-10-31 20:21:00 +08:00
parent a4eb7fa900
commit c80c8f907c
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
13 changed files with 285 additions and 60 deletions

View file

@ -1,5 +1,7 @@
package json
import "context"
func UnmarshalDisallowUnknownFields(data []byte, v any) error {
var d decodeState
d.disallowUnknownFields = true
@ -10,3 +12,15 @@ func UnmarshalDisallowUnknownFields(data []byte, v any) error {
d.init(data)
return d.unmarshal(v)
}
func UnmarshalContextDisallowUnknownFields(ctx context.Context, data []byte, v any) error {
var d decodeState
d.ctx = ctx
d.disallowUnknownFields = true
err := checkValid(data, &d.scan)
if err != nil {
return err
}
d.init(data)
return d.unmarshal(v)
}