File: format_decode.jq

package info (click to toggle)
fq 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 106,624 kB
  • sloc: xml: 2,835; makefile: 250; sh: 241; exp: 57; ansic: 21
file content (17 lines) | stat: -rw-r--r-- 675 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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")