mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 20:37:40 +03:00
badjson: Add context marshaler/unmarshaler
This commit is contained in:
parent
a4eb7fa900
commit
c80c8f907c
13 changed files with 285 additions and 60 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue