mirror of
https://github.com/wader/fq.git
synced 2024-11-23 00:57:15 +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.
18 lines
675 B
Plaintext
18 lines
675 B
Plaintext
# note this is a "dynamic" include, output string will be used as source
|
|
|
|
# generates decode functions, ex:
|
|
# mp3/0 calls decode("mp3"; {})
|
|
# mp3/1 calls decode("mp3"; $opts)
|
|
# from_mp3/* same but throws error on decode error
|
|
|
|
[ _registry as $r
|
|
| $r.groups
|
|
| to_entries[]
|
|
# skip_decode_function is used to skip bits/bytes as they are special tobits/tobytes
|
|
| select($r.formats[.key].skip_decode_function | not)
|
|
| "def \(.key)($opts): decode(\(.key | tojson); $opts);"
|
|
, "def \(.key): decode(\(.key | tojson); {});"
|
|
, "def from_\(.key)($opts): decode(\(.key | tojson); $opts) | if ._error then error(._error.error) end;"
|
|
, "def from_\(.key): from_\(.key)({});"
|
|
] | join("\n")
|