mirror of https://github.com/goccy/go-json.git
Fix decoder option flag
This commit is contained in:
parent
a69176cd30
commit
34b7053412
|
@ -39,7 +39,7 @@ func unmarshal(data []byte, v interface{}, optFuncs ...DecodeOptionFunc) error {
|
||||||
}
|
}
|
||||||
ctx := decoder.TakeRuntimeContext()
|
ctx := decoder.TakeRuntimeContext()
|
||||||
ctx.Buf = src
|
ctx.Buf = src
|
||||||
ctx.Option.FirstWin = false
|
ctx.Option.Flag = 0
|
||||||
for _, optFunc := range optFuncs {
|
for _, optFunc := range optFuncs {
|
||||||
optFunc(ctx.Option)
|
optFunc(ctx.Option)
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func unmarshalNoEscape(data []byte, v interface{}, optFuncs ...DecodeOptionFunc)
|
||||||
|
|
||||||
ctx := decoder.TakeRuntimeContext()
|
ctx := decoder.TakeRuntimeContext()
|
||||||
ctx.Buf = src
|
ctx.Buf = src
|
||||||
ctx.Option.FirstWin = false
|
ctx.Option.Flag = 0
|
||||||
for _, optFunc := range optFuncs {
|
for _, optFunc := range optFuncs {
|
||||||
optFunc(ctx.Option)
|
optFunc(ctx.Option)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package decoder
|
package decoder
|
||||||
|
|
||||||
|
type OptionFlag int
|
||||||
|
|
||||||
|
const (
|
||||||
|
FirstWinOption OptionFlag = 1 << iota
|
||||||
|
)
|
||||||
|
|
||||||
type Option struct {
|
type Option struct {
|
||||||
FirstWin bool
|
Flag OptionFlag
|
||||||
}
|
}
|
||||||
|
|
|
@ -727,7 +727,7 @@ func (d *structDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsaf
|
||||||
seenFields map[int]struct{}
|
seenFields map[int]struct{}
|
||||||
seenFieldNum int
|
seenFieldNum int
|
||||||
)
|
)
|
||||||
firstWin := ctx.Option.FirstWin
|
firstWin := (ctx.Option.Flag & FirstWinOption) != 0
|
||||||
if firstWin {
|
if firstWin {
|
||||||
seenFields = make(map[int]struct{}, d.fieldUniqueNameNum)
|
seenFields = make(map[int]struct{}, d.fieldUniqueNameNum)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,6 @@ type DecodeOptionFunc func(*DecodeOption)
|
||||||
|
|
||||||
func DecodeFieldPriorityFirstWin() DecodeOptionFunc {
|
func DecodeFieldPriorityFirstWin() DecodeOptionFunc {
|
||||||
return func(opt *DecodeOption) {
|
return func(opt *DecodeOption) {
|
||||||
opt.FirstWin = true
|
opt.Flag |= decoder.FirstWinOption
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue