mirror of
https://github.com/wader/fq.git
synced 2024-11-24 11:16:09 +03:00
1b32b42f93
Generate more code More generic and comfortable API Improve and Update format decoder to new API Add some more format tests
240 lines
13 KiB
Plaintext
240 lines
13 KiB
Plaintext
$ fq -d mp3 '.headers[0].magic._bits[8:16] | hd' /test.mp3
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0| 44 | D |.: raw bits 0x1-0x1.7 (1)
|
|
$ fq -d mp3 '.headers[0].magic._bits | [.[8:16], .[0:8]] | hd' /test.mp3
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|44 49| |DI| |.: raw bits 0x0-0x1.7 (2)
|
|
$ fq -d mp3 '.headers[0].magic._bits | [.[8:16], .[0:8]] | tobits | hd' /test.mp3
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|44 49| |DI| |.: raw bits 0x0-0x1.7 (2)
|
|
$ fq -d mp3 '.headers[0].magic._bits | [.[8:16], .[0:8]] | tobytes | hd' /test.mp3
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|44 49| |DI| |.: raw bits 0x0-0x1.7 (2)
|
|
$ fq -n '"12" | tobytes | hd'
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|31 32| |12| |.: raw bits 0x0-0x1.7 (2)
|
|
$ fq -n '"12" | tobits | hd'
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|31 32| |12| |.: raw bits 0x0-0x1.7 (2)
|
|
$ fq -n '["12", "3"] | tobytes | hd'
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|31 32 33| |123| |.: raw bits 0x0-0x2.7 (3)
|
|
$ fq -n '["12", "3"] | tobits | hd'
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|31 32 33| |123| |.: raw bits 0x0-0x2.7 (3)
|
|
$ fq -n '[("11" | hex), ("22" | hex)] | tobits | hd'
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|11 22| |."| |.: raw bits 0x0-0x1.7 (2)
|
|
# TODO: bug, hexdump uses io.Copy which is byte oritneted
|
|
$ fq -n '[("12" | hex | .bits[4:]), ("34" | hex | .bits[0:4])] | tobits | hd'
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|20| | | |.: raw bits 0x0-0x0.7 (1)
|
|
$ fq -d mp3 '.frames[]._bits[0:12] | tonumber' /test.mp3
|
|
4095
|
|
4095
|
|
4095
|
|
$ fq -d mp3 '.headers[0].magic._bits[0:24] | tostring' /test.mp3
|
|
"ID3"
|
|
$ fq -d mp3 '.frames[0].padding | ("", "md5", "base64", "snippet") as $f | tovalue({bits_format: $f})' /test.mp3
|
|
"<5>AAAAAAA="
|
|
"ca9c491ac66b2c62500882e93f3719a8"
|
|
"AAAAAAA="
|
|
"<5>AAAAAAA="
|
|
$ fq -d mp3 -i . /test.mp3
|
|
mp3> [1, 2, 3] | tobytes
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|01 02 03| |...| |.: raw bits 0x0-0x2.7 (3)
|
|
mp3> [1, 2, 3, [1, 2, 3]] | tobytes
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|01 02 03 01 02 03| |......| |.: raw bits 0x0-0x5.7 (6)
|
|
mp3> [1, 2, 3, [1, 2, 3], .headers[0].magic] | tobytes
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|01 02 03 01 02 03 49 44 33| |......ID3| |.: raw bits 0x0-0x8.7 (9)
|
|
mp3> [-1] | tobytes
|
|
error: buffer byte list must be bytes (0-255) got -1
|
|
mp3> [256] | tobytes
|
|
error: buffer byte list must be bytes (0-255) got 256
|
|
mp3> ^D
|
|
$ fq -d mp3 -i . /test.mp3
|
|
mp3> .frames[1] | tobits | ., .start, .stop, .size, .[4:17], (tobits, tobytes, tobitsrange, tobytesrange | ., .start, .stop, .size, .[4:17])
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
1664
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|ff fb 50 |..P |.: raw bits 0x0.4-0x2 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
1664
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|ff fb 50 |..P |.: raw bits 0x0.4-0x2 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
208
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00| 00 00 0a 2c 43 2e 55 94 80 01 80 93| ...,C.U.....|.: raw bits 0x4-0x10.7 (13)
|
|
0x10|6b |k |
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
1664
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|ff fb 50 |..P |.: raw bits 0x0.4-0x2 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
208
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00| 00 00 0a 2c 43 2e 55 94 80 01 80 93| ...,C.U.....|.: raw bits 0x4-0x10.7 (13)
|
|
0x10|6b |k |
|
|
mp3> .frames[1] | tobytes | ., .start, .stop, .size, .[4:17], (tobits, tobytes, tobitsrange, tobytesrange | ., .start, .stop, .size, .[4:17])
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
208
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00| 00 00 0a 2c 43 2e 55 94 80 01 80 93| ...,C.U.....|.: raw bits 0x4-0x10.7 (13)
|
|
0x10|6b |k |
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
1664
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|ff fb 50 |..P |.: raw bits 0x0.4-0x2 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
208
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00| 00 00 0a 2c 43 2e 55 94 80 01 80 93| ...,C.U.....|.: raw bits 0x4-0x10.7 (13)
|
|
0x10|6b |k |
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
1664
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|ff fb 50 |..P |.: raw bits 0x0.4-0x2 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
208
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00| 00 00 0a 2c 43 2e 55 94 80 01 80 93| ...,C.U.....|.: raw bits 0x4-0x10.7 (13)
|
|
0x10|6b |k |
|
|
mp3> .frames[1] | tobitsrange | ., .start, .stop, .size, .[4:17], (tobits, tobytes, tobitsrange, tobytesrange | ., .start, .stop, .size, .[4:17])
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0e0| ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80| ..P....,C.U..|.: raw bits 0xe3-0x1b2.7 (208)
|
|
0x0f0|01 80 93 6b 27 30 80 00 07 aa c3 8e 33 85 d3 64|...k'0......3..d|
|
|
* |until 0x1b2.7 (208) | |
|
|
1816
|
|
3480
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0xe0| ff fb 50 | ..P |.: raw bits 0xe3.4-0xe5 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
1664
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|ff fb 50 |..P |.: raw bits 0x0.4-0x2 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
208
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00| 00 00 0a 2c 43 2e 55 94 80 01 80 93| ...,C.U.....|.: raw bits 0x4-0x10.7 (13)
|
|
0x10|6b |k |
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0e0| ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80| ..P....,C.U..|.: raw bits 0xe3-0x1b2.7 (208)
|
|
0x0f0|01 80 93 6b 27 30 80 00 07 aa c3 8e 33 85 d3 64|...k'0......3..d|
|
|
* |until 0x1b2.7 (208) | |
|
|
1816
|
|
3480
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0xe0| ff fb 50 | ..P |.: raw bits 0xe3.4-0xe5 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0e0| ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80| ..P....,C.U..|.: raw bits 0xe3-0x1b2.7 (208)
|
|
0x0f0|01 80 93 6b 27 30 80 00 07 aa c3 8e 33 85 d3 64|...k'0......3..d|
|
|
* |until 0x1b2.7 (208) | |
|
|
227
|
|
435
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0xe0| 00 00 0a 2c 43 2e 55 94 80| ...,C.U..|.: raw bits 0xe7-0xf3.7 (13)
|
|
0xf0|01 80 93 6b |...k |
|
|
mp3> .frames[1] | tobytesrange | ., .start, .stop, .size, .[4:17], (tobits, tobytes, tobitsrange, tobytesrange | ., .start, .stop, .size, .[4:17])
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0e0| ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80| ..P....,C.U..|.: raw bits 0xe3-0x1b2.7 (208)
|
|
0x0f0|01 80 93 6b 27 30 80 00 07 aa c3 8e 33 85 d3 64|...k'0......3..d|
|
|
* |until 0x1b2.7 (208) | |
|
|
227
|
|
435
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0xe0| 00 00 0a 2c 43 2e 55 94 80| ...,C.U..|.: raw bits 0xe7-0xf3.7 (13)
|
|
0xf0|01 80 93 6b |...k |
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
1664
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0|ff fb 50 |..P |.: raw bits 0x0.4-0x2 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00|ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80 01 80 93|..P....,C.U.....|.: raw bits 0x0-0xcf.7 (208)
|
|
* |until 0xcf.7 (end) (208) | |
|
|
0
|
|
208
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x00| 00 00 0a 2c 43 2e 55 94 80 01 80 93| ...,C.U.....|.: raw bits 0x4-0x10.7 (13)
|
|
0x10|6b |k |
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0e0| ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80| ..P....,C.U..|.: raw bits 0xe3-0x1b2.7 (208)
|
|
0x0f0|01 80 93 6b 27 30 80 00 07 aa c3 8e 33 85 d3 64|...k'0......3..d|
|
|
* |until 0x1b2.7 (208) | |
|
|
1816
|
|
3480
|
|
1664
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0xe0| ff fb 50 | ..P |.: raw bits 0xe3.4-0xe5 (1.5)
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0x0e0| ff fb 50 c4 00 00 0a 2c 43 2e 55 94 80| ..P....,C.U..|.: raw bits 0xe3-0x1b2.7 (208)
|
|
0x0f0|01 80 93 6b 27 30 80 00 07 aa c3 8e 33 85 d3 64|...k'0......3..d|
|
|
* |until 0x1b2.7 (208) | |
|
|
227
|
|
435
|
|
208
|
|
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
|
|
0xe0| 00 00 0a 2c 43 2e 55 94 80| ...,C.U..|.: raw bits 0xe7-0xf3.7 (13)
|
|
0xf0|01 80 93 6b |...k |
|
|
mp3> ^D
|