From 64e17f0ece7744319a49d7f73d41f5b3dd665a0e Mon Sep 17 00:00:00 2001 From: bump Date: Wed, 7 Jun 2023 16:03:58 +0000 Subject: [PATCH 1/9] Update docker-golang to 1.20.5 from 1.20.4 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5d22f636e..2afcb0cfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # bump: docker-golang /FROM golang:([\d.]+)/ docker:golang|^1 -FROM golang:1.20.4-bullseye AS base +FROM golang:1.20.5-bullseye AS base # expect is used to test cli RUN \ From 6faed67512cb83f66f490f9fd7aad836c43fe10a Mon Sep 17 00:00:00 2001 From: bump Date: Wed, 7 Jun 2023 16:04:05 +0000 Subject: [PATCH 2/9] Update github-go-version to 1.20.5 from 1.20.4 --- .github/workflows/ci.yml | 4 ++-- .github/workflows/release.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 123023e6a..2ce3b999b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: "1.20.4" + go-version: "1.20.5" - uses: actions/checkout@v3 - uses: golangci/golangci-lint-action@v3 with: @@ -47,7 +47,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.20.4" + go-version: "1.20.5" - name: Test env: GOARCH: ${{ matrix.goarch }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5bda56cec..a3301e487 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.20.4" + go-version: "1.20.5" - uses: goreleaser/goreleaser-action@v2 with: distribution: goreleaser From 87bf8f174b04366d3953ff794e3f9b2387997294 Mon Sep 17 00:00:00 2001 From: Michael B Date: Tue, 13 Jun 2023 16:57:38 +0200 Subject: [PATCH 3/9] wip: adjust bit header; add comments --- pkg/interp/dump.go | 53 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/pkg/interp/dump.go b/pkg/interp/dump.go index f3b66e7d3..757cd3c04 100644 --- a/pkg/interp/dump.go +++ b/pkg/interp/dump.go @@ -12,6 +12,7 @@ import ( "github.com/wader/fq/internal/binwriter" "github.com/wader/fq/internal/bitioex" "github.com/wader/fq/internal/columnwriter" + "github.com/wader/fq/internal/hexpairwriter" "github.com/wader/fq/internal/mathex" "github.com/wader/fq/pkg/bitio" "github.com/wader/fq/pkg/decode" @@ -33,6 +34,9 @@ const ( colField = 6 ) +// 2: binary, 16: hex, others: TODO +const outputBase = 2 + const rootIndentWidth = 2 const treeIndentWidth = 2 @@ -72,6 +76,7 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD cprint := func(c int, a ...any) { fmt.Fprint(cw.Columns[c], a...) } + // cfmt: column i fmt.fprintf cfmt := func(c int, format string, a ...any) { fmt.Fprintf(cw.Columns[c], format, a...) } @@ -118,7 +123,9 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD // show address bar on root, nested root and format change if depth == 0 || v.IsRoot || v.Format != nil { + // write header: 00 01 02 03 04 cfmt(colHex, "%s", deco.DumpHeader.F(ctx.hexHeader)) + // write header: 012345 cfmt(colASCII, "%s", deco.DumpHeader.F(ctx.asciiHeader)) if willDisplayData { @@ -272,6 +279,7 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD // has length and is not compound or a collapsed struct/array (max depth) if willDisplayData { + // write: 0x00012 (example address) cfmt(colAddr, "%s%s\n", rootIndent, deco.DumpAddr.F(mathex.PadFormatInt(startLineByte, opts.Addrbase, true, addrWidth))) @@ -286,7 +294,7 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD } addrLines := lastDisplayLine - startLine + 1 - // hexpairFn := func(b byte) string { return deco.ByteColor(b).Wrap(hexpairwriter.Pair(b)) } + hexpairFn := func(b byte) string { return deco.ByteColor(b).Wrap(hexpairwriter.Pair(b)) } binFn := func(b byte) string { return deco.ByteColor(b).Wrap(string("01"[int(b)])) } asciiFn := func(b byte) string { return deco.ByteColor(b).Wrap(asciiwriter.SafeASCII(b)) } @@ -294,20 +302,26 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD if err != nil { return err } - // if _, err := bitioex.CopyBitsBuffer( - // hexpairwriter.New(cw.Columns[colHex], opts.LineBytes, int(startLineByteOffset), hexpairFn), - // hexBR, - // buf); err != nil { - // return err - // } - - if _, err := bitio.CopyBuffer( - binwriter.New(cw.Columns[colHex], opts.LineBytes*8, int(startLineBitOffset), binFn), - hexBR, - buf); err != nil { - return err - } + switch outputBase { + case 16: + // write: 89 50 4e 47 0d 0a 1a 0a + if _, err := bitioex.CopyBitsBuffer( + hexpairwriter.New(cw.Columns[colHex], opts.LineBytes, int(startLineByteOffset), hexpairFn), + hexBR, + buf); err != nil { + return err + } + case 2: + // write: 100010010101000001 + if _, err := bitio.CopyBuffer( + binwriter.New(cw.Columns[colHex], opts.LineBytes*8, int(startLineBitOffset), binFn), + hexBR, + buf); err != nil { + return err + } + } + // write: .PNG.... asciiBR, err := bitio.CloneReadSeeker(vBR) if err != nil { return err @@ -406,11 +420,18 @@ func dump(v *decode.Value, w io.Writer, opts *Options) error { var hexHeader string var asciiHeader string + var spaceLength int + switch outputBase { + case 16: + spaceLength = 1 + case 2: + spaceLength = 8 - 2 // TODO: adapt for wider screens + } for i := 0; i < opts.LineBytes; i++ { s := mathex.PadFormatInt(int64(i), opts.Addrbase, false, 2) hexHeader += s - if i < opts.LineBytes-1 { - hexHeader += " " + if spaceLength > 1 || i < opts.LineBytes-1 { + hexHeader += strings.Repeat(" ", spaceLength) } asciiHeader += s[len(s)-1:] } From aac413f353982ad1d8d9c8899cc623f8019d40a2 Mon Sep 17 00:00:00 2001 From: Michael B Date: Tue, 13 Jun 2023 17:28:47 +0200 Subject: [PATCH 4/9] wip: fix adaptive hexColumnWidth --- pkg/interp/dump.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/interp/dump.go b/pkg/interp/dump.go index 757cd3c04..cf9940a9e 100644 --- a/pkg/interp/dump.go +++ b/pkg/interp/dump.go @@ -397,7 +397,13 @@ func dump(v *decode.Value, w io.Writer, opts *Options) error { } addrColumnWidth := maxAddrIndentWidth - hexColumnWidth := opts.LineBytes * 8 + var hexColumnWidth int + switch outputBase { + case 16: + hexColumnWidth = opts.LineBytes*3 - 1 + case 2: + hexColumnWidth = opts.LineBytes * 8 + } asciiColumnWidth := opts.LineBytes treeColumnWidth := -1 // TODO: set with and truncate/wrap properly From 6dc0746adca555fccb4b4e6584ae6533cf1d790b Mon Sep 17 00:00:00 2001 From: bump Date: Tue, 13 Jun 2023 16:04:08 +0000 Subject: [PATCH 5/9] Update gomod-golang-x-crypto to 0.10.0 from 0.9.0 Tags https://github.com/golang/crypto/tags --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index baf71954f..0fc5db91d 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,7 @@ require ( // bump: gomod-golang-x-crypto /golang\.org\/x\/crypto v(.*)/ https://github.com/golang/crypto.git|^0 // bump: gomod-golang-x-crypto command go get -d golang.org/x/crypto@v$LATEST && go mod tidy // bump: gomod-golang-x-crypto link "Tags" https://github.com/golang/crypto/tags - golang.org/x/crypto v0.9.0 + golang.org/x/crypto v0.10.0 // has no tags // go get -d golang.org/x/exp@master && go mod tidy @@ -66,7 +66,7 @@ require ( // bump: gomod-golang/text /golang\.org\/x\/text v(.*)/ https://github.com/golang/text.git|^0 // bump: gomod-golang/text command go get -d golang.org/x/text@v$LATEST && go mod tidy // bump: gomod-golang/text link "Source diff $CURRENT..$LATEST" https://github.com/golang/text/compare/v$CURRENT..v$LATEST - golang.org/x/text v0.9.0 + golang.org/x/text v0.10.0 // bump: gomod-gopkg.in/yaml.v3 /gopkg\.in\/yaml\.v3 v(.*)/ https://github.com/go-yaml/yaml.git|^3 // bump: gomod-gopkg.in/yaml.v3 command go get -d gopkg.in/yaml.v3@v$LATEST && go mod tidy @@ -78,6 +78,6 @@ require ( github.com/itchyny/timefmt-go v0.1.5 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect - golang.org/x/sys v0.8.0 // indirect + golang.org/x/sys v0.9.0 // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect ) diff --git a/go.sum b/go.sum index 856dd5242..1dfd45d2a 100644 --- a/go.sum +++ b/go.sum @@ -27,18 +27,18 @@ github.com/wader/gojq v0.12.1-0.20230529153812-b7e613069119 h1:9GNJxrBtaN5wHFGap github.com/wader/gojq v0.12.1-0.20230529153812-b7e613069119/go.mod h1:jQY39j9tgky+JYcJrKNz5OYTe/sPDAw7FvVj13JGqVk= github.com/wader/readline v0.0.0-20230307172220-bcb7158e7448 h1:AzpBtmgdXa3uznrb3esNeEoaLqtNEwckRmaUH0qWD6w= github.com/wader/readline v0.0.0-20230307172220-bcb7158e7448/go.mod h1:Zgz8IJWvJoe7NK23CCPpC109XMCqJCpUhpHcnnA4XaM= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= +golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 h1:BEABXpNXLEz0WxtA+6CQIz2xkg80e+1zrhWyMcq8VzE= golang.org/x/exp v0.0.0-20230131160201-f062dba9d201/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= From 939d98c27c6ecb6aedb62986687e118fc7ac1e8f Mon Sep 17 00:00:00 2001 From: bump Date: Tue, 13 Jun 2023 16:04:11 +0000 Subject: [PATCH 6/9] Update gomod-golang-x-net to 0.11.0 from 0.10.0 Tags https://github.com/golang/net/tags --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index baf71954f..9d55cc52d 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,7 @@ require ( // bump: gomod-golang-x-crypto /golang\.org\/x\/crypto v(.*)/ https://github.com/golang/crypto.git|^0 // bump: gomod-golang-x-crypto command go get -d golang.org/x/crypto@v$LATEST && go mod tidy // bump: gomod-golang-x-crypto link "Tags" https://github.com/golang/crypto/tags - golang.org/x/crypto v0.9.0 + golang.org/x/crypto v0.10.0 // has no tags // go get -d golang.org/x/exp@master && go mod tidy @@ -61,12 +61,12 @@ require ( // bump: gomod-golang-x-net /golang\.org\/x\/net v(.*)/ https://github.com/golang/net.git|^0 // bump: gomod-golang-x-net command go get -d golang.org/x/net@v$LATEST && go mod tidy // bump: gomod-golang-x-net link "Tags" https://github.com/golang/net/tags - golang.org/x/net v0.10.0 + golang.org/x/net v0.11.0 // bump: gomod-golang/text /golang\.org\/x\/text v(.*)/ https://github.com/golang/text.git|^0 // bump: gomod-golang/text command go get -d golang.org/x/text@v$LATEST && go mod tidy // bump: gomod-golang/text link "Source diff $CURRENT..$LATEST" https://github.com/golang/text/compare/v$CURRENT..v$LATEST - golang.org/x/text v0.9.0 + golang.org/x/text v0.10.0 // bump: gomod-gopkg.in/yaml.v3 /gopkg\.in\/yaml\.v3 v(.*)/ https://github.com/go-yaml/yaml.git|^3 // bump: gomod-gopkg.in/yaml.v3 command go get -d gopkg.in/yaml.v3@v$LATEST && go mod tidy @@ -78,6 +78,6 @@ require ( github.com/itchyny/timefmt-go v0.1.5 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect - golang.org/x/sys v0.8.0 // indirect + golang.org/x/sys v0.9.0 // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect ) diff --git a/go.sum b/go.sum index 856dd5242..b3a3a83d3 100644 --- a/go.sum +++ b/go.sum @@ -27,18 +27,18 @@ github.com/wader/gojq v0.12.1-0.20230529153812-b7e613069119 h1:9GNJxrBtaN5wHFGap github.com/wader/gojq v0.12.1-0.20230529153812-b7e613069119/go.mod h1:jQY39j9tgky+JYcJrKNz5OYTe/sPDAw7FvVj13JGqVk= github.com/wader/readline v0.0.0-20230307172220-bcb7158e7448 h1:AzpBtmgdXa3uznrb3esNeEoaLqtNEwckRmaUH0qWD6w= github.com/wader/readline v0.0.0-20230307172220-bcb7158e7448/go.mod h1:Zgz8IJWvJoe7NK23CCPpC109XMCqJCpUhpHcnnA4XaM= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= +golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 h1:BEABXpNXLEz0WxtA+6CQIz2xkg80e+1zrhWyMcq8VzE= golang.org/x/exp v0.0.0-20230131160201-f062dba9d201/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= +golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= From 36ef2a20b50d5c09799450dce11c79e3c1c7e708 Mon Sep 17 00:00:00 2001 From: bump Date: Tue, 13 Jun 2023 16:04:14 +0000 Subject: [PATCH 7/9] Update gomod-golang/text to 0.10.0 from 0.9.0 Source diff 0.9.0..0.10.0 https://github.com/golang/text/compare/v0.9.0..v0.10.0 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index baf71954f..c454c47cc 100644 --- a/go.mod +++ b/go.mod @@ -66,7 +66,7 @@ require ( // bump: gomod-golang/text /golang\.org\/x\/text v(.*)/ https://github.com/golang/text.git|^0 // bump: gomod-golang/text command go get -d golang.org/x/text@v$LATEST && go mod tidy // bump: gomod-golang/text link "Source diff $CURRENT..$LATEST" https://github.com/golang/text/compare/v$CURRENT..v$LATEST - golang.org/x/text v0.9.0 + golang.org/x/text v0.10.0 // bump: gomod-gopkg.in/yaml.v3 /gopkg\.in\/yaml\.v3 v(.*)/ https://github.com/go-yaml/yaml.git|^3 // bump: gomod-gopkg.in/yaml.v3 command go get -d gopkg.in/yaml.v3@v$LATEST && go mod tidy diff --git a/go.sum b/go.sum index 856dd5242..eb998e4eb 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,8 @@ golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= From 0473afea2bd020fe2ebcf1715f8d7434765796f2 Mon Sep 17 00:00:00 2001 From: Michael B Date: Wed, 14 Jun 2023 12:00:45 +0200 Subject: [PATCH 8/9] wip: add base to options --- pkg/interp/dump.go | 11 ++++------- pkg/interp/interp.go | 1 + pkg/interp/options.jq | 19 +++++++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pkg/interp/dump.go b/pkg/interp/dump.go index cf9940a9e..f6d415a9f 100644 --- a/pkg/interp/dump.go +++ b/pkg/interp/dump.go @@ -34,9 +34,6 @@ const ( colField = 6 ) -// 2: binary, 16: hex, others: TODO -const outputBase = 2 - const rootIndentWidth = 2 const treeIndentWidth = 2 @@ -303,7 +300,7 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD return err } - switch outputBase { + switch opts.Base { case 16: // write: 89 50 4e 47 0d 0a 1a 0a if _, err := bitioex.CopyBitsBuffer( @@ -313,7 +310,7 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD return err } case 2: - // write: 100010010101000001 + // write: 100010010101000 if _, err := bitio.CopyBuffer( binwriter.New(cw.Columns[colHex], opts.LineBytes*8, int(startLineBitOffset), binFn), hexBR, @@ -398,7 +395,7 @@ func dump(v *decode.Value, w io.Writer, opts *Options) error { addrColumnWidth := maxAddrIndentWidth var hexColumnWidth int - switch outputBase { + switch opts.Base { case 16: hexColumnWidth = opts.LineBytes*3 - 1 case 2: @@ -427,7 +424,7 @@ func dump(v *decode.Value, w io.Writer, opts *Options) error { var hexHeader string var asciiHeader string var spaceLength int - switch outputBase { + switch opts.Base { case 16: spaceLength = 1 case 2: diff --git a/pkg/interp/interp.go b/pkg/interp/interp.go index 700674ec6..1acf8a974 100644 --- a/pkg/interp/interp.go +++ b/pkg/interp/interp.go @@ -1044,6 +1044,7 @@ type Options struct { BitsFormat string LineBytes int DisplayBytes int + Base int Addrbase int Sizebase int SkipGaps bool diff --git a/pkg/interp/options.jq b/pkg/interp/options.jq index 35f14a15a..29bb27765 100644 --- a/pkg/interp/options.jq +++ b/pkg/interp/options.jq @@ -78,6 +78,7 @@ def _opt_options: argdecode: "array_string_pair", argjson: "array_string_pair", array_truncate: "number", + base: "number", bits_format: "string", byte_colors: "csv_ranges_array", color: "boolean", @@ -528,12 +529,26 @@ def options($opts): + [$opts] ) | add - | ( if .width != 0 then [_intdiv(_intdiv(.width; 8); 2) * 2, 4] | max - else 16 + # set input data hex/bits to ~37.5% of width + | ( if .width != 0 then + _intdiv(.width; 8) * 3 + else + 16 * 3 + end + ) as $input_data_width + | ( if .base == 2 then + # 100010010101000 + # show at least 1 byte + [_intdiv($input_data_width; 8), 1] | max + else + # 89 50 4e 47 0d 0a 1a 0a + # show an even amount of bytes; and at least 4 + [_intdiv(_intdiv($input_data_width; 3); 2) * 2, 4] | max end ) as $display_bytes # default if not set | .display_bytes |= (. // $display_bytes) | .line_bytes |= (. // $display_bytes) + | .base |= (. // 16) ); def options: options({}); From 8d0164cdb20617f787bae6a109771dc926fdf5c2 Mon Sep 17 00:00:00 2001 From: Michael B Date: Wed, 14 Jun 2023 13:41:28 +0200 Subject: [PATCH 9/9] wip: adapt data width for bits --- pkg/interp/dump.go | 52 ++++++++++++++++++++++++++++++------------- pkg/interp/options.jq | 9 ++++++-- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/pkg/interp/dump.go b/pkg/interp/dump.go index f6d415a9f..d8bd570a1 100644 --- a/pkg/interp/dump.go +++ b/pkg/interp/dump.go @@ -192,6 +192,10 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD cprint(colField, "\n") + // -------------------------------------------------- + // Error handling + // -------------------------------------------------- + if valueErr != nil { var printErrs func(depth int, err error) printErrs = func(depth int, err error) { @@ -227,24 +231,33 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD printErrs(depth, valueErr) } + // -------------------------------------------------- + // For a given field, compute various helper variables + // -------------------------------------------------- + rootBitLen, err := bitioex.Len(rootV.RootReader) if err != nil { return err } bufferLastBit := rootBitLen - 1 - startBit := innerRange.Start - stopBit := innerRange.Stop() - 1 - sizeBits := innerRange.Len - lastDisplayBit := stopBit + startBit := innerRange.Start // field's start bit index (for entire file) + stopBit := innerRange.Stop() - 1 // field's end bit index (for entire file); inclusive + sizeBits := innerRange.Len // field's bit length (1, 8, 16, 32, ...) - if opts.DisplayBytes > 0 && sizeBits > int64(opts.DisplayBytes)*8 { - lastDisplayBit = startBit + (int64(opts.DisplayBytes)*8 - 1) - if lastDisplayBit%(int64(opts.LineBytes)*8) != 0 { - lastDisplayBit += (int64(opts.LineBytes) * 8) - lastDisplayBit%(int64(opts.LineBytes)*8) - 1 + // determine lastDisplayBit: + // sometimes the field's bit length overflows the max width of a line; + // cut off the overflow in such cases. + lastDisplayBit := stopBit + displayBits := int64(opts.DisplayBytes) * 8 + lineBits := int64(opts.LineBytes) * 8 + if opts.DisplayBytes > 0 && sizeBits > displayBits { + lastDisplayBit = startBit + (displayBits - 1) + if lastDisplayBit%lineBits != 0 { + lastDisplayBit += lineBits - lastDisplayBit%lineBits - 1 } - if lastDisplayBit > stopBit || stopBit-lastDisplayBit <= int64(opts.LineBytes)*8 { + if lastDisplayBit > stopBit || stopBit-lastDisplayBit <= lineBits { lastDisplayBit = stopBit } } @@ -274,13 +287,17 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD startLineByte := startLine * int64(opts.LineBytes) lastDisplayLine := lastDisplayByte / int64(opts.LineBytes) + // -------------------------------------------------- + // Ouput Data + // -------------------------------------------------- + // has length and is not compound or a collapsed struct/array (max depth) if willDisplayData { // write: 0x00012 (example address) cfmt(colAddr, "%s%s\n", rootIndent, deco.DumpAddr.F(mathex.PadFormatInt(startLineByte, opts.Addrbase, true, addrWidth))) - vBR, err := bitioex.Range(rootV.RootReader, startByte*4, displaySizeBits) + vBR1, err := bitioex.Range(rootV.RootReader, startByte*8, displaySizeBits) if err != nil { return err } @@ -295,14 +312,13 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD binFn := func(b byte) string { return deco.ByteColor(b).Wrap(string("01"[int(b)])) } asciiFn := func(b byte) string { return deco.ByteColor(b).Wrap(asciiwriter.SafeASCII(b)) } - hexBR, err := bitio.CloneReadSeeker(vBR2) - if err != nil { - return err - } - switch opts.Base { case 16: // write: 89 50 4e 47 0d 0a 1a 0a + hexBR, err := bitio.CloneReadSeeker(vBR1) + if err != nil { + return err + } if _, err := bitioex.CopyBitsBuffer( hexpairwriter.New(cw.Columns[colHex], opts.LineBytes, int(startLineByteOffset), hexpairFn), hexBR, @@ -311,6 +327,10 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD } case 2: // write: 100010010101000 + hexBR, err := bitio.CloneReadSeeker(vBR2) + if err != nil { + return err + } if _, err := bitio.CopyBuffer( binwriter.New(cw.Columns[colHex], opts.LineBytes*8, int(startLineBitOffset), binFn), hexBR, @@ -319,7 +339,7 @@ func dumpEx(v *decode.Value, ctx *dumpCtx, depth int, rootV *decode.Value, rootD } } // write: .PNG.... - asciiBR, err := bitio.CloneReadSeeker(vBR) + asciiBR, err := bitio.CloneReadSeeker(vBR1) if err != nil { return err } diff --git a/pkg/interp/options.jq b/pkg/interp/options.jq index 29bb27765..4b9ad1db0 100644 --- a/pkg/interp/options.jq +++ b/pkg/interp/options.jq @@ -529,9 +529,14 @@ def options($opts): + [$opts] ) | add - # set input data hex/bits to ~37.5% of width | ( if .width != 0 then - _intdiv(.width; 8) * 3 + if .base == 2 then + # set input data bits to ~44.4% of width + .5 * (8 / (8 + 1)) * .width | floor + else + # set input data hex to ~37.5% of width + .5 * (3 / (3 + 1)) * .width | floor + end else 16 * 3 end