Skip to content

Commit

Permalink
interp: Wrap Binary in decodeValue to fix prompt issue with bits/byte…
Browse files Browse the repository at this point in the history
…s format
  • Loading branch information
wader committed Jan 4, 2023
1 parent 162cb40 commit 8b49b42
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions format/bits/testdata/test.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 5 additions & 2 deletions pkg/interp/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/interp/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/interp/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/interp/testdata/repl.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8b49b42

Please sign in to comment.