mirror of
https://github.com/wader/fq.git
synced 2024-09-11 20:07:11 +03:00
Compare commits
8 Commits
072588c24b
...
56beac25b0
Author | SHA1 | Date | |
---|---|---|---|
|
56beac25b0 | ||
|
c0cde303f4 | ||
|
33f785cac7 | ||
|
8bb841f0ce | ||
|
de3fa199e4 | ||
|
72e026ef78 | ||
|
2c38cf1324 | ||
|
790aa8aac2 |
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -7,7 +7,7 @@ on:
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOLANGCILINT_VERSION: "1.59.1"
|
||||
GOLANGCILINT_VERSION: "1.60.1"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
@ -15,7 +15,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: "1.22.6"
|
||||
go-version: "1.23.0"
|
||||
- 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.22.6"
|
||||
go-version: "1.23.0"
|
||||
- name: Test
|
||||
env:
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: "1.22.6"
|
||||
go-version: "1.23.0"
|
||||
- uses: goreleaser/goreleaser-action@v5
|
||||
with:
|
||||
distribution: goreleaser
|
||||
|
@ -1,5 +1,5 @@
|
||||
# bump: docker-golang /FROM golang:([\d.]+)/ docker:golang|^1
|
||||
FROM golang:1.22.6-bookworm AS base
|
||||
FROM golang:1.23.0-bookworm AS base
|
||||
|
||||
# expect is used to test cli
|
||||
RUN \
|
||||
|
2
Makefile
2
Makefile
@ -61,7 +61,7 @@ gogenerate: always
|
||||
lint: always
|
||||
# bump: make-golangci-lint /golangci-lint@v([\d.]+)/ git:https://github.com/golangci/golangci-lint.git|^1
|
||||
# bump: make-golangci-lint link "Release notes" https://github.com/golangci/golangci-lint/releases/tag/v$LATEST
|
||||
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run
|
||||
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 run
|
||||
|
||||
depgraph.svg: always
|
||||
go run github.com/kisielk/godepgraph@latest github.com/wader/fq | dot -Tsvg -o godepgraph.svg
|
||||
|
@ -243,7 +243,7 @@ apk add -X http://dl-cdn.alpinelinux.org/alpine/edge/testing fq
|
||||
|
||||
### Build from source
|
||||
|
||||
Make sure you have [go](https://go.dev) 1.20 or later installed.
|
||||
Make sure you have [go](https://go.dev) 1.21 or later installed.
|
||||
|
||||
To install directly from git repository (no git clone needed):
|
||||
```sh
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/wader/fq/format"
|
||||
"github.com/wader/fq/internal/mathx"
|
||||
"github.com/wader/fq/pkg/bitio"
|
||||
"github.com/wader/fq/pkg/decode"
|
||||
"github.com/wader/fq/pkg/interp"
|
||||
@ -65,7 +64,7 @@ func flacDecode(d *decode.D) any {
|
||||
|
||||
samplesInFrame := ffo.Samples
|
||||
if streamTotalSamples > 0 {
|
||||
samplesInFrame = mathx.Min(streamTotalSamples-streamDecodedSamples, ffo.Samples)
|
||||
samplesInFrame = min(streamTotalSamples-streamDecodedSamples, ffo.Samples)
|
||||
}
|
||||
frameStreamSamplesBuf := ffo.SamplesBuf[0 : samplesInFrame*uint64(ffo.Channels*ffo.BitsPerSample/8)]
|
||||
framesNDecodedSamples += ffo.Samples
|
||||
|
@ -5,7 +5,6 @@ package icc
|
||||
|
||||
import (
|
||||
"github.com/wader/fq/format"
|
||||
"github.com/wader/fq/internal/mathx"
|
||||
"github.com/wader/fq/pkg/decode"
|
||||
"github.com/wader/fq/pkg/interp"
|
||||
"github.com/wader/fq/pkg/scalar"
|
||||
@ -167,7 +166,7 @@ func iccProfileDecode(d *decode.D) any {
|
||||
// was. instead add alignment after if offset+size does not align and to be sure clamp it if outside buffer.
|
||||
alignStart := int64(offset) + int64(size)
|
||||
alignBytes := (4 - (int64(offset)+int64(size))%4) % 4
|
||||
alignBytes = mathx.Min(d.Len()/8-alignStart, alignBytes)
|
||||
alignBytes = min(d.Len()/8-alignStart, alignBytes)
|
||||
if alignBytes != 0 {
|
||||
d.RangeFn(alignStart*8, alignBytes*8, func(d *decode.D) {
|
||||
d.FieldRawLen("alignment", d.BitsLeft())
|
||||
|
@ -53,7 +53,7 @@ func decodeJSONEx(d *decode.D, lines bool) any {
|
||||
break
|
||||
}
|
||||
} else if lines {
|
||||
d.Fatalf(err.Error())
|
||||
d.Fatalf("%s", err.Error())
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ package leveldb
|
||||
// - MANIFEST-*
|
||||
|
||||
import (
|
||||
"github.com/wader/fq/internal/mathx"
|
||||
"github.com/wader/fq/pkg/decode"
|
||||
"github.com/wader/fq/pkg/scalar"
|
||||
)
|
||||
@ -49,7 +48,7 @@ func readBlockSequence(rro recordReadOptions, d *decode.D) {
|
||||
|
||||
d.FieldArray("blocks", func(d *decode.D) {
|
||||
for d.BitsLeft() >= headerSize {
|
||||
d.LimitedFn(mathx.Min(blockSize, d.BitsLeft()), func(d *decode.D) {
|
||||
d.LimitedFn(min(blockSize, d.BitsLeft()), func(d *decode.D) {
|
||||
d.FieldStruct("block", bind(readLogBlock, rro))
|
||||
})
|
||||
}
|
||||
|
@ -470,7 +470,6 @@ func matroskaDecode(d *decode.D) any {
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("expected mpegASCOut got %#+v", v))
|
||||
}
|
||||
//nolint:gosimple
|
||||
t.formatInArg = format.AAC_Frame_In{ObjectType: mpegASCOut.ObjectType}
|
||||
case "A_OPUS":
|
||||
t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, &opusPacketFrameGroup, nil)
|
||||
@ -494,14 +493,14 @@ func matroskaDecode(d *decode.D) any {
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("expected AvcDcrOut got %#+v", v))
|
||||
}
|
||||
t.formatInArg = format.AVC_AU_In{LengthSize: avcDcrOut.LengthSize} //nolint:gosimple
|
||||
t.formatInArg = format.AVC_AU_In{LengthSize: avcDcrOut.LengthSize}
|
||||
case "V_MPEGH/ISO/HEVC":
|
||||
_, v := t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, &mpegHEVCDCRGroup, nil)
|
||||
hevcDcrOut, ok := v.(format.HEVC_DCR_Out)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("expected HevcDcrOut got %#+v", v))
|
||||
}
|
||||
t.formatInArg = format.HEVC_AU_In{LengthSize: hevcDcrOut.LengthSize} //nolint:gosimple
|
||||
t.formatInArg = format.HEVC_AU_In{LengthSize: hevcDcrOut.LengthSize}
|
||||
case "V_AV1":
|
||||
t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, &av1CCRGroup, nil)
|
||||
case "V_VP9":
|
||||
|
@ -133,7 +133,7 @@ func mp3Decode(d *decode.D) any {
|
||||
|
||||
unknownPercent := int(float64((d.Len() - knownSize)) / float64(d.Len()) * 100.0)
|
||||
if unknownPercent > mi.MaxUnknown {
|
||||
d.Errorf(fmt.Sprintf("exceeds max precent unknown bits, %d > %d", unknownPercent, mi.MaxUnknown))
|
||||
d.Errorf("exceeds max precent unknown bits, %d > %d", unknownPercent, mi.MaxUnknown)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -711,7 +711,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
|
||||
panic(fmt.Sprintf("expected AvcDcrOut got %#+v", v))
|
||||
}
|
||||
if t := ctx.currentTrack(); t != nil {
|
||||
t.formatInArg = format.AVC_AU_In{LengthSize: avcDcrOut.LengthSize} //nolint:gosimple
|
||||
t.formatInArg = format.AVC_AU_In{LengthSize: avcDcrOut.LengthSize}
|
||||
}
|
||||
case "hvcC":
|
||||
_, v := d.FieldFormat("descriptor", &hevcCDCRGroup, nil)
|
||||
@ -720,7 +720,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
|
||||
panic(fmt.Sprintf("expected HevcDcrOut got %#+v", v))
|
||||
}
|
||||
if t := ctx.currentTrack(); t != nil {
|
||||
t.formatInArg = format.HEVC_AU_In{LengthSize: hevcDcrOut.LengthSize} //nolint:gosimple
|
||||
t.formatInArg = format.HEVC_AU_In{LengthSize: hevcDcrOut.LengthSize}
|
||||
}
|
||||
case "dfLa":
|
||||
d.FieldU8("version")
|
||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
module github.com/wader/fq
|
||||
|
||||
go 1.20
|
||||
go 1.21
|
||||
|
||||
// fork of github.com/itchyny/gojq, see github.com/wader/gojq fq branch
|
||||
require github.com/wader/gojq v0.12.1-0.20240401131232-6c6bc364201a
|
||||
|
@ -85,7 +85,7 @@ func (d *Dumper) WriteBits(p []byte, nBits int64) (n int64, err error) {
|
||||
pos := int64(0)
|
||||
rBits := nBits
|
||||
if d.bitsBufN > 0 {
|
||||
r := mathx.Min(8-d.bitsBufN, nBits)
|
||||
r := min(8-d.bitsBufN, nBits)
|
||||
v := bitio.Read64(p, 0, r)
|
||||
bitio.Write64(v, r, d.bitsBuf, d.bitsBufN)
|
||||
|
||||
|
@ -54,28 +54,8 @@ func PadFormatBigInt(i *big.Int, base int, basePrefix bool, width int) string {
|
||||
return padFormatNumber(i.Text(base), base, basePrefix, width)
|
||||
}
|
||||
|
||||
func Max[T constraints.Ordered](v T, vs ...T) T {
|
||||
m := v
|
||||
for _, v := range vs {
|
||||
if v > m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func Min[T constraints.Ordered](v T, vs ...T) T {
|
||||
m := v
|
||||
for _, v := range vs {
|
||||
if v < m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func Clamp[T constraints.Ordered](min, max, v T) T {
|
||||
return Max(min, Min(max, v))
|
||||
func Clamp[T constraints.Ordered](a, b, v T) T {
|
||||
return max(a, min(b, v))
|
||||
}
|
||||
|
||||
type Bits uint64
|
||||
|
@ -1,11 +1,9 @@
|
||||
package stringsx
|
||||
|
||||
import "github.com/wader/fq/internal/mathx"
|
||||
|
||||
func TrimN(s string, n int, suffix string) string {
|
||||
sl, tl := len(s), len(suffix)
|
||||
if sl+tl <= n {
|
||||
return s
|
||||
}
|
||||
return s[0:mathx.Max(n-tl, 0)] + suffix
|
||||
return s[0:max(n-tl, 0)] + suffix
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/wader/fq/internal/mathx"
|
||||
"github.com/wader/fq/pkg/interp"
|
||||
"golang.org/x/term"
|
||||
|
||||
@ -92,7 +91,7 @@ type fdTerminal uintptr
|
||||
func (fd fdTerminal) Size() (int, int) {
|
||||
w, h, _ := term.GetSize(int(fd))
|
||||
// TODO: old version return 0 on no terminal
|
||||
w, h = mathx.Max(0, w), mathx.Max(0, h)
|
||||
w, h = max(0, w), max(0, h)
|
||||
return w, h
|
||||
}
|
||||
func (fd fdTerminal) IsTerminal() bool {
|
||||
|
@ -169,7 +169,7 @@ func (d *D) tryTextLenPrefixed(prefixLenBytes int, fixedBytes int, e encoding.En
|
||||
if fixedBytes != -1 {
|
||||
// TODO: error?
|
||||
readBytes = fixedBytes - prefixLenBytes
|
||||
lenBytes = mathx.Min(lenBytes, uint64(readBytes))
|
||||
lenBytes = min(lenBytes, uint64(readBytes))
|
||||
}
|
||||
|
||||
bs, err := d.TryBytesLen(readBytes)
|
||||
|
@ -350,7 +350,7 @@ func dump(v *decode.Value, w io.Writer, opts *Options) error {
|
||||
}
|
||||
|
||||
_ = v.WalkPreOrder(makeWalkFn(func(v *decode.Value, _ *decode.Value, _ int, rootDepth int) error {
|
||||
maxAddrIndentWidth = mathx.Max(
|
||||
maxAddrIndentWidth = max(
|
||||
maxAddrIndentWidth,
|
||||
rootIndentWidth*rootDepth+mathx.DigitsInBase(bitio.BitsByteCount(v.InnerRange().Stop()), true, opts.Addrbase),
|
||||
)
|
||||
|
@ -1057,13 +1057,13 @@ type Options struct {
|
||||
func OptionsFromValue(v any) (*Options, error) {
|
||||
var opts Options
|
||||
_ = mapstruct.ToStruct(v, &opts)
|
||||
opts.ArrayTruncate = mathx.Max(0, opts.ArrayTruncate)
|
||||
opts.StringTruncate = mathx.Max(0, opts.StringTruncate)
|
||||
opts.Depth = mathx.Max(0, opts.Depth)
|
||||
opts.ArrayTruncate = max(0, opts.ArrayTruncate)
|
||||
opts.StringTruncate = max(0, opts.StringTruncate)
|
||||
opts.Depth = max(0, opts.Depth)
|
||||
opts.Addrbase = mathx.Clamp(2, 36, opts.Addrbase)
|
||||
opts.Sizebase = mathx.Clamp(2, 36, opts.Sizebase)
|
||||
opts.LineBytes = mathx.Max(1, opts.LineBytes)
|
||||
opts.DisplayBytes = mathx.Max(0, opts.DisplayBytes)
|
||||
opts.LineBytes = max(1, opts.LineBytes)
|
||||
opts.DisplayBytes = max(0, opts.DisplayBytes)
|
||||
opts.Decorator = decoratorFromOptions(opts)
|
||||
if fn, err := bitsFormatFnFromOptions(opts); err != nil {
|
||||
return nil, err
|
||||
|
@ -9,20 +9,6 @@ import (
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func max(a, b int64) int64 {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func min(a, b int64) int64 {
|
||||
if a > b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
type Range struct {
|
||||
Start int64
|
||||
Len int64
|
||||
|
Loading…
Reference in New Issue
Block a user