mirror of
https://github.com/wader/fq.git
synced 2024-12-25 14:23:18 +03:00
Merge pull request #413 from wader/decode-remove-rangesort
decode: Remove RangeSorted flag as we can decide on array/struct instead
This commit is contained in:
commit
df1a81ed26
@ -168,7 +168,6 @@ func newDecoder(ctx context.Context, format Format, br bitio.ReaderAtSeeker, opt
|
||||
}
|
||||
rootV := &Compound{
|
||||
IsArray: format.RootArray,
|
||||
RangeSorted: !format.RootArray,
|
||||
Children: nil,
|
||||
Description: opts.Description,
|
||||
}
|
||||
@ -765,7 +764,7 @@ func (d *D) FieldMustGet(name string) *Value {
|
||||
|
||||
// FieldArray decode array of fields. Will not be range sorted.
|
||||
func (d *D) FieldArray(name string, fn func(d *D), sms ...scalar.Mapper) *D {
|
||||
c := &Compound{IsArray: true, RangeSorted: false}
|
||||
c := &Compound{IsArray: true}
|
||||
cd := d.fieldDecoder(name, d.bitBuf, c)
|
||||
d.AddChild(cd.Value)
|
||||
fn(cd)
|
||||
@ -779,7 +778,7 @@ func (d *D) FieldArrayValue(name string) *D {
|
||||
|
||||
// FieldStruct decode array of fields. Will be range sorted.
|
||||
func (d *D) FieldStruct(name string, fn func(d *D)) *D {
|
||||
c := &Compound{IsArray: false, RangeSorted: true}
|
||||
c := &Compound{IsArray: false}
|
||||
cd := d.fieldDecoder(name, d.bitBuf, c)
|
||||
d.AddChild(cd.Value)
|
||||
fn(cd)
|
||||
@ -1104,7 +1103,7 @@ func (d *D) FieldRootBitBuf(name string, br bitio.ReaderAtSeeker, sms ...scalar.
|
||||
}
|
||||
|
||||
func (d *D) FieldArrayRootBitBufFn(name string, br bitio.ReaderAtSeeker, fn func(d *D)) *Value {
|
||||
c := &Compound{IsArray: true, RangeSorted: false}
|
||||
c := &Compound{IsArray: true}
|
||||
cd := d.fieldDecoder(name, br, c)
|
||||
cd.Value.IsRoot = true
|
||||
d.AddChild(cd.Value)
|
||||
@ -1116,7 +1115,7 @@ func (d *D) FieldArrayRootBitBufFn(name string, br bitio.ReaderAtSeeker, fn func
|
||||
}
|
||||
|
||||
func (d *D) FieldStructRootBitBufFn(name string, br bitio.ReaderAtSeeker, fn func(d *D)) *Value {
|
||||
c := &Compound{IsArray: false, RangeSorted: true}
|
||||
c := &Compound{IsArray: false}
|
||||
cd := d.fieldDecoder(name, br, c)
|
||||
cd.Value.IsRoot = true
|
||||
d.AddChild(cd.Value)
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
|
||||
type Compound struct {
|
||||
IsArray bool
|
||||
RangeSorted bool
|
||||
Children []*Value
|
||||
ByName map[string]*Value
|
||||
Description string
|
||||
@ -198,10 +197,9 @@ func (v *Value) postProcess() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: really sort array? if sort it needs to be stable to keep the order
|
||||
// of value with same range start, think null values etc
|
||||
if vv.RangeSorted {
|
||||
slices.SortFunc(vv.Children, func(a, b *Value) bool { return a.Range.Start < b.Range.Start })
|
||||
// sort struct fields and make sure to keep order if range is the same
|
||||
if !vv.IsArray {
|
||||
slices.SortStableFunc(vv.Children, func(a, b *Value) bool { return a.Range.Start < b.Range.Start })
|
||||
}
|
||||
|
||||
v.Index = -1
|
||||
|
Loading…
Reference in New Issue
Block a user