1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 05:13:30 +03:00

interp: Wrap Binary in decodeValue to fix prompt issue with bits/bytes format

This commit is contained in:
Mattias Wadman 2023-01-04 13:08:01 +01:00
parent 162cb40d9f
commit 8b49b42fa3
5 changed files with 14 additions and 6 deletions

View File

@ -2,13 +2,13 @@
hello
$ fq -d bits '., .size, .[8:-8]' hello
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0|68 65 6c 6c 6f 0a| |hello.| |.: raw bits 0x0-0x5.7 (6)
0x0|68 65 6c 6c 6f 0a| |hello.| |.: raw bits (bits)
48
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0| 65 6c 6c 6f | ello |.: raw bits 0x1-0x4.7 (4)
$ fq -d bytes '., .size, .[1:-1]' hello
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0|68 65 6c 6c 6f 0a| |hello.| |.: raw bits 0x0-0x5.7 (6)
0x0|68 65 6c 6c 6f 0a| |hello.| |.: raw bits (bytes)
6
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0| 65 6c 6c 6f | ello |.: raw bits 0x1-0x4.7 (4)

View File

@ -433,8 +433,11 @@ func makeDecodeValueOut(dv *decode.Value, kind decodeValueKind, out any) any {
decodeValueBase: decodeValueBase{dv: dv},
}
case Binary:
// used by bytes and bits format
return vvv
return decodeValue{
JQValue: vvv,
decodeValueBase: decodeValueBase{dv: dv},
}
default:
panic(fmt.Sprintf("unreachable vv %#+v", vvv))
}

View File

@ -49,7 +49,9 @@ func decoratorFromOptions(opts Options) Decorator {
return d.True
}
return d.False
case string, bitio.Reader:
case string,
bitio.Reader,
Binary:
return d.String
case int, float64, int64, uint64:
// TODO: clean up number types

View File

@ -42,7 +42,8 @@ func previewValue(v any, df scalar.DisplayFormat) string {
return strings.ReplaceAll(s, `\u007f`, `\x7f`)
case nil:
return "null"
case bitio.Reader:
case bitio.Reader,
Binary:
return "raw bits"
case *big.Int:
return mathex.PadFormatBigInt(vv, df.FormatBase(), true, 0)

View File

@ -107,6 +107,8 @@ $ fq -i -d json . test.mp3
json!> ^D
$ fq -i -n '"[]" | json'
json> ^D
$ fq -i -d bytes . test.mp3
bytes> ^D
$ fq -n repl
exitcode: 3
stderr: