forked from mirror/go-json
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.Buf = src
|
||||
ctx.Option.FirstWin = false
|
||||
ctx.Option.Flag = 0
|
||||
for _, optFunc := range optFuncs {
|
||||
optFunc(ctx.Option)
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func unmarshalNoEscape(data []byte, v interface{}, optFuncs ...DecodeOptionFunc)
|
|||
|
||||
ctx := decoder.TakeRuntimeContext()
|
||||
ctx.Buf = src
|
||||
ctx.Option.FirstWin = false
|
||||
ctx.Option.Flag = 0
|
||||
for _, optFunc := range optFuncs {
|
||||
optFunc(ctx.Option)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package decoder
|
||||
|
||||
type OptionFlag int
|
||||
|
||||
const (
|
||||
FirstWinOption OptionFlag = 1 << iota
|
||||
)
|
||||
|
||||
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{}
|
||||
seenFieldNum int
|
||||
)
|
||||
firstWin := ctx.Option.FirstWin
|
||||
firstWin := (ctx.Option.Flag & FirstWinOption) != 0
|
||||
if firstWin {
|
||||
seenFields = make(map[int]struct{}, d.fieldUniqueNameNum)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue