1
1
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:
Mattias Wadman 2022-08-08 18:17:51 +02:00 committed by GitHub
commit 4dec7ff64b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 34 deletions

View File

@ -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
}

View File

@ -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()

View File

@ -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
})

View File

@ -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

View File

@ -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