1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 13:22:58 +03:00
fq/pkg/interp/format_decode.jq
Mattias Wadman e3ae1440c9 interp: Rename to/from<format> functions to to_/from_<format>
Feels less cluttered, easier to read and more consistent.

Still keep tovalue, tobytes etc that are more basic functions this
only renamed format related functions.
Also there is an exceptin for to/fromjson as it comes from jq.

Also fixes lots of spelling errors while reading thru.
2022-12-21 17:48:39 +01:00

19 lines
767 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[]
# TODO: nicer way to skip "all" which also would override builtin all/*
# skip_decode_function is used to skip bits/bytes as they are special tobits/tobytes
| select(.key != "all" and ($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")