mirror of
https://github.com/wader/fq.git
synced 2024-12-19 19:31:37 +03:00
b08ef00dd1
Replaces []Format with a Group type. A bit more type safe. Breaking change for RegisterFormat, now takes a first argument that is a "single" format group. Lots of naming cleanup. This is also preparation for decode group argument which will enable doing intresting probing, ex a format decoder could know it's decode as part of probe group (html could be probed possibly), or have "arg probe" group for decoder who inspect args to know if they should probe (-d /path/to/schema etc) to enable nice CLI-ergonomics.
35 lines
652 B
Go
35 lines
652 B
Go
package decode
|
|
|
|
type Group struct {
|
|
Name string
|
|
Formats []*Format
|
|
DefaultInArg any
|
|
}
|
|
|
|
type Dependency struct {
|
|
Groups []*Group
|
|
Out *Group
|
|
}
|
|
|
|
type Format struct {
|
|
Name string
|
|
ProbeOrder int // probe order is from low to hi value then by name
|
|
Description string
|
|
Groups []*Group
|
|
DecodeFn func(d *D) any
|
|
DefaultInArg any
|
|
RootArray bool
|
|
RootName string
|
|
Dependencies []Dependency
|
|
Functions []string
|
|
SkipDecodeFunction bool
|
|
}
|
|
|
|
func FormatFn(fn func(d *D) any) *Group {
|
|
return &Group{
|
|
Formats: []*Format{
|
|
{DecodeFn: fn},
|
|
},
|
|
}
|
|
}
|