mirror of
https://github.com/wader/fq.git
synced 2024-11-28 03:02:55 +03:00
Merge pull request #364 from wader/decode-refactor-scalar-type-assert
decode: Refactor to use scalar type assert helper
This commit is contained in:
commit
4dec7ff64b
@ -353,11 +353,7 @@ func strIndexNull(idx int, s string) string {
|
||||
type strTable string
|
||||
|
||||
func (m strTable) MapScalar(s scalar.S) (scalar.S, error) {
|
||||
uv, ok := s.Actual.(uint64)
|
||||
if !ok {
|
||||
return s, nil
|
||||
}
|
||||
s.Sym = strIndexNull(int(uv), string(m))
|
||||
s.Sym = strIndexNull(int(s.ActualU()), string(m))
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
@ -49,14 +49,6 @@ func decodeJSON(d *decode.D, _ any) any {
|
||||
}
|
||||
|
||||
s.Actual = gojq.NormalizeNumbers(s.Actual)
|
||||
|
||||
// switch s.Actual.(type) {
|
||||
// case map[string]any,
|
||||
// []any:
|
||||
// default:
|
||||
// d.Fatalf("top-level not object or array")
|
||||
// }
|
||||
|
||||
d.Value.V = &s
|
||||
d.Value.Range.Len = d.Len()
|
||||
|
||||
|
@ -819,11 +819,7 @@ func parseSectionFlags(d *decode.D) {
|
||||
}
|
||||
|
||||
var timestampMapper = scalar.Fn(func(s scalar.S) (scalar.S, error) {
|
||||
ts, ok := s.Actual.(uint64)
|
||||
if !ok {
|
||||
return s, nil
|
||||
}
|
||||
s.Sym = time.UnixMilli(int64(ts)).UTC().String()
|
||||
s.Sym = time.UnixMilli(int64(s.ActualU())).UTC().String()
|
||||
return s, nil
|
||||
})
|
||||
|
||||
|
@ -11,10 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func bitBufIsZero(s scalar.S, isValidate bool) (scalar.S, error) {
|
||||
br, ok := s.Actual.(bitio.ReaderAtSeeker)
|
||||
if !ok {
|
||||
return s, nil
|
||||
}
|
||||
br := s.ActualBitBuf()
|
||||
|
||||
isZero := true
|
||||
// TODO: shared
|
||||
|
@ -136,10 +136,7 @@ type URangeEntry struct {
|
||||
type URangeToScalar []URangeEntry
|
||||
|
||||
func (rs URangeToScalar) MapScalar(s S) (S, error) {
|
||||
n, ok := s.Actual.(uint64)
|
||||
if !ok {
|
||||
return s, nil
|
||||
}
|
||||
n := s.ActualU()
|
||||
for _, re := range rs {
|
||||
if n >= re.Range[0] && n <= re.Range[1] {
|
||||
ns := re.S
|
||||
@ -161,10 +158,7 @@ type SRangeEntry struct {
|
||||
type SRangeToScalar []SRangeEntry
|
||||
|
||||
func (rs SRangeToScalar) MapScalar(s S) (S, error) {
|
||||
n, ok := s.Actual.(int64)
|
||||
if !ok {
|
||||
return s, nil
|
||||
}
|
||||
n := s.ActualS()
|
||||
for _, re := range rs {
|
||||
if n >= re.Range[0] && n <= re.Range[1] {
|
||||
ns := re.S
|
||||
@ -177,10 +171,7 @@ func (rs SRangeToScalar) MapScalar(s S) (S, error) {
|
||||
}
|
||||
|
||||
func RawSym(s S, nBytes int, fn func(b []byte) string) (S, error) {
|
||||
br, ok := s.Actual.(bitio.ReadAtSeeker)
|
||||
if !ok {
|
||||
return s, nil
|
||||
}
|
||||
br := s.ActualBitBuf()
|
||||
brLen, err := bitioextra.Len(br)
|
||||
if err != nil {
|
||||
return S{}, err
|
||||
|
Loading…
Reference in New Issue
Block a user