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

interp,format: Refactor registry usage and use function helpers

Move registry to interp and add support for functions and filesystems.
This will be used later for allow formats to add own functions and fq code.

Add gojqextra function helpers to have more comfortable API to add functions.
Takes care of argument type casting and JQValue:s and some more things.

Refactor interp package to use new function helper and registry. Probably
fixes a bunch of JQValue bugs and other type errors.

Refactor out some mpeg nal things to mpeg format.

Refactor interp jq code into display.q and init.jq.

Remove undocumented aes_ctr funciton, was a test. Hopefully will add more crypto things laster.
This commit is contained in:
Mattias Wadman 2022-07-16 18:39:57 +02:00
parent 88dc847441
commit 1ddea1ada3
135 changed files with 1343 additions and 1115 deletions

View File

@ -43,7 +43,7 @@ func main() {
min := toInt(args[0])
max := toInt(args[1])
var v []int
for i := min; i <= max; i++ {
for i := min; i < max; i++ {
v = append(v, i)
}
@ -60,6 +60,16 @@ func main() {
return strings.Replace(s, o, n, -1), nil
},
"slice": func(args ...any) []any {
return args
},
"map": func(args ...any) map[any]any {
m := map[any]any{}
for i := 0; i < len(args)/2; i++ {
m[args[i*2]] = args[i*2+1]
}
return m
},
}
data := map[string]any{}

View File

@ -4,14 +4,14 @@ package ape
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var imageFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.APEV2,
Description: "APEv2 metadata tag",
DecodeFn: apev2Decode,

View File

@ -2,15 +2,15 @@ package ar
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var probeFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AR,
Description: "Unix archive",
Groups: []string{format.PROBE},

View File

@ -22,9 +22,9 @@ import (
"strings"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -32,7 +32,7 @@ import (
var asn1FS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ASN1_BER,
Description: "ASN1 BER (basic encoding rules, also CER and DER)",
DecodeFn: decodeASN1BER,

View File

@ -6,13 +6,13 @@ package av1
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AV1_CCR,
Description: "AV1 Codec Configuration Record",
DecodeFn: ccrDecode,

View File

@ -6,14 +6,14 @@ package av1
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var obuFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AV1_FRAME,
Description: "AV1 frame",
DecodeFn: frameDecode,

View File

@ -2,13 +2,13 @@ package av1
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AV1_OBU,
Description: "AV1 Open Bitstream Unit",
DecodeFn: obuDecode,

View File

@ -10,9 +10,9 @@ import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/avro/decoders"
"github.com/wader/fq/format/avro/schema"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -20,7 +20,7 @@ import (
var avroOcfFS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AVRO_OCF,
Description: "Avro object container file",
Groups: []string{format.PROBE},

View File

@ -7,8 +7,8 @@ import (
"strconv"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -16,7 +16,7 @@ import (
var bencodeFS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.BENCODE,
Description: "BitTorrent bencoding",
DecodeFn: decodeBencode,

View File

@ -2,14 +2,14 @@ package bitcoin
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var bitcoinBlockFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.BITCOIN_BLKDAT,
Description: "Bitcoin blk.dat",
Groups: []string{format.PROBE},

View File

@ -6,15 +6,15 @@ import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var bitcoinTranscationFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.BITCOIN_BLOCK,
Description: "Bitcoin block",
Dependencies: []decode.Dependency{

View File

@ -2,8 +2,8 @@ package bitcoin
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -34,7 +34,7 @@ func (ops opcodeEntries) MapScalar(s scalar.S) (scalar.S, error) {
}
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.BITCOIN_SCRIPT,
Description: "Bitcoin script",
DecodeFn: decodeBitcoinScript,

View File

@ -6,15 +6,15 @@ package bitcoin
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var bitcoinScriptFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.BITCOIN_TRANSACTION,
Description: "Bitcoin transaction",
Dependencies: []decode.Dependency{

View File

@ -7,8 +7,8 @@ import (
"embed"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -16,7 +16,7 @@ import (
var bsonFS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.BSON,
Description: "Binary JSON",
DecodeFn: decodeBSON,

View File

@ -13,16 +13,16 @@ import (
"math/bits"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var probeGroup decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.BZIP2,
Description: "bzip2 compression",
Groups: []string{format.PROBE},

View File

@ -13,10 +13,10 @@ import (
"strings"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/internal/mathextra"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -24,7 +24,7 @@ import (
var cborFS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.CBOR,
Description: "Concise Binary Object Representation",
DecodeFn: decodeCBOR,

View File

@ -8,13 +8,13 @@ import (
"strings"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.DNS,
Description: "DNS packet",
Groups: []string{

View File

@ -2,12 +2,12 @@ package dns
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.DNS_TCP,
Description: "DNS packet (TCP)",
DecodeFn: dnsTCPDecode,

View File

@ -11,13 +11,13 @@ import (
"strings"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ELF,
Description: "Executable and Linkable Format",
Groups: []string{format.PROBE},

View File

@ -4,12 +4,12 @@ package fairplay
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.FAIRPLAY_SPC,
Description: "FairPlay Server Playback Context",
DecodeFn: fairPlaySPCDecode,

View File

@ -12,10 +12,10 @@ import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/internal/mathextra"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -23,7 +23,7 @@ var flacMetadatablocksFormat decode.Group
var flacFrameFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.FLAC,
Description: "Free Lossless Audio Codec file",
Groups: []string{format.PROBE},

View File

@ -5,15 +5,15 @@ import (
"math/bits"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/internal/mathextra"
"github.com/wader/fq/pkg/checksum"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.FLAC_FRAME,
Description: "FLAC frame",
DecodeFn: frameDecode,

View File

@ -7,8 +7,8 @@ import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -17,7 +17,7 @@ var flacPicture decode.Group
var vorbisCommentFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.FLAC_METADATABLOCK,
Description: "FLAC metadatablock",
DecodeFn: metadatablockDecode,

View File

@ -4,14 +4,14 @@ import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var flacMetadatablockFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.FLAC_METADATABLOCKS,
Description: "FLAC metadatablocks",
DecodeFn: metadatablocksDecode,

View File

@ -2,8 +2,8 @@ package flac
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -34,7 +34,7 @@ var pictureTypeNames = scalar.UToSymStr{
}
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.FLAC_PICTURE,
Description: "FLAC metadatablock picture",
DecodeFn: pictureDecode,

View File

@ -2,13 +2,13 @@ package flac
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.FLAC_STREAMINFO,
Description: "FLAC streaminfo",
DecodeFn: streaminfoDecode,

View File

@ -7,8 +7,8 @@ package flv
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/registry"
"github.com/wader/fq/pkg/scalar"
)

View File

@ -4,10 +4,10 @@ import (
"testing"
_ "github.com/wader/fq/format/all"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/fqtest"
"github.com/wader/fq/pkg/interp"
)
func TestFQTests(t *testing.T) {
fqtest.TestPath(t, registry.Default)
fqtest.TestPath(t, interp.DefaultRegister)
}

View File

@ -14,9 +14,9 @@ import (
"testing"
_ "github.com/wader/fq/format/all"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/registry"
)
type fuzzFS struct{}
@ -99,11 +99,11 @@ func FuzzFormats(f *testing.F) {
})
gi := 0
g := registry.Default.MustAll()
g := interp.DefaultRegister.MustAll()
f.Fuzz(func(t *testing.T, b []byte) {
fz := &fuzzTest{b: b, f: g[gi]}
q, err := interp.New(fz, registry.Default)
q, err := interp.New(fz, interp.DefaultRegister)
if err != nil {
t.Fatal(err)
}

View File

@ -11,13 +11,13 @@ import (
"bytes"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.GIF,
Description: "Graphics Interchange Format",
Groups: []string{format.PROBE, format.IMAGE},

View File

@ -10,15 +10,15 @@ import (
"io"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var probeFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.GZIP,
Description: "gzip compression",
Groups: []string{format.PROBE},

View File

@ -5,13 +5,13 @@ package icc
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/internal/mathextra"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ICC_PROFILE,
Description: "International Color Consortium profile",
DecodeFn: iccProfileDecode,

View File

@ -2,15 +2,15 @@ package id3
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
// TODO: comment 28 long, zero byte, track number
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ID3V1,
Description: "ID3v1 metadata",
DecodeFn: id3v1Decode,

View File

@ -2,13 +2,13 @@ package id3
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ID3V11,
Description: "ID3v1.1 metadata",
DecodeFn: id3v11Decode,

View File

@ -10,9 +10,9 @@ import (
"strings"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
@ -22,7 +22,7 @@ import (
var imageFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ID3V2,
Description: "ID3v2 metadata",
DecodeFn: id3v2Decode,

View File

@ -4,15 +4,15 @@ package inet
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var bsdLoopbackFrameInetPacketGroup decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.BSD_LOOPBACK_FRAME,
Description: "BSD loopback frame",
Groups: []string{format.LINK_FRAME},

View File

@ -7,15 +7,15 @@ import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var ether8023FrameInetPacketGroup decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ETHER8023_FRAME,
Description: "Ethernet 802.3 frame",
Groups: []string{format.LINK_FRAME},

View File

@ -2,13 +2,13 @@ package inet
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ICMP,
Description: "Internet Control Message Protocol",
Groups: []string{format.IP_PACKET},

View File

@ -2,13 +2,13 @@ package inet
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ICMPV6,
Description: "Internet Control Message Protocol v6",
Groups: []string{format.IP_PACKET},

View File

@ -5,17 +5,17 @@ import (
"net"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/checksum"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var ipv4IpPacketGroup decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.IPV4_PACKET,
Description: "Internet protocol v4 packet",
Groups: []string{format.INET_PACKET},

View File

@ -5,16 +5,16 @@ import (
"net"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/internal/bitioextra"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var ipv6IpPacketGroup decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.IPV6_PACKET,
Description: "Internet protocol v6 packet",
Groups: []string{format.INET_PACKET},

View File

@ -5,15 +5,15 @@ package inet
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var sllPacket2InetPacketGroup decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.SLL2_PACKET,
Description: "Linux cooked capture encapsulation v2",
Groups: []string{format.LINK_FRAME},

View File

@ -5,15 +5,15 @@ package inet
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var sllPacketInetPacketGroup decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.SLL_PACKET,
Description: "Linux cooked capture encapsulation",
Groups: []string{format.LINK_FRAME},

View File

@ -4,13 +4,13 @@ package inet
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.TCP_SEGMENT,
Description: "Transmission control protocol segment",
Groups: []string{format.IP_PACKET},

View File

@ -2,15 +2,15 @@ package inet
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var udpPayloadGroup decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.UDP_DATAGRAM,
Description: "User datagram protocol",
Groups: []string{format.IP_PACKET},

View File

@ -8,9 +8,9 @@ import (
"bytes"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -18,7 +18,7 @@ var exifFormat decode.Group
var iccProfileFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.JPEG,
Description: "Joint Photographic Experts Group file",
Groups: []string{format.PROBE, format.IMAGE},

View File

@ -4,9 +4,9 @@ import (
stdjson "encoding/json"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -16,7 +16,7 @@ import (
// TODO: use jd.InputOffset() * 8?
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.JSON,
Description: "JSON",
ProbeOrder: 100, // last

View File

@ -7,9 +7,9 @@ import (
"time"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -17,7 +17,7 @@ import (
var machoFS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MACHO,
Description: "Mach-O macOS executable",
Groups: []string{format.PROBE},

View File

@ -20,8 +20,8 @@ import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/matroska/ebml"
"github.com/wader/fq/format/matroska/ebml_matroska"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/ranges"
"github.com/wader/fq/pkg/scalar"
)
@ -52,7 +52,7 @@ var vp9FrameFormat decode.Group
var codecToFormat map[string]*decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MATROSKA,
Description: "Matroska file",
Groups: []string{format.PROBE},
@ -153,7 +153,9 @@ func decodeMaster(d *decode.D, bitsLimit int64, tag ebml.Tag, dc *decodeContext)
for d.Pos() < tagEndBit && d.NotEnd() {
d.FieldStruct("element", func(d *decode.D) {
var a ebml.Attribute
a := ebml.Attribute{
Type: ebml.Unknown,
}
tagID := d.FieldUFn("id", decodeRawVint, scalar.Fn(func(s scalar.S) (scalar.S, error) {
n := s.ActualU()

View File

@ -6,8 +6,8 @@ import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var headerFormat decode.Group
@ -15,7 +15,7 @@ var footerFormat decode.Group
var mp3Frame decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MP3,
ProbeOrder: 20, // after most others (silent samples and jpeg header can look like mp3 sync)
Description: "MP3 file",

View File

@ -4,12 +4,12 @@ package mp3
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.XING,
Description: "Xing header",
DecodeFn: xingDecode,

View File

@ -21,8 +21,8 @@ import (
"sort"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
//go:embed mp4.jq
@ -52,7 +52,7 @@ var vpxCCRFormat decode.Group
var iccProfileFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MP4,
Description: "ISOBMFF MPEG-4 part 12 and similar",
Groups: []string{

View File

@ -2,13 +2,13 @@ package mp4
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.PSSH_PLAYREADY,
Description: "PlayReady PSSH",
DecodeFn: playreadyPsshDecode,

View File

@ -8,13 +8,13 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AAC_FRAME,
Description: "Advanced Audio Coding frame",
DecodeFn: aacDecode,

View File

@ -2,14 +2,14 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var adtsFrame decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ADTS,
Description: "Audio Data Transport Stream",
Groups: []string{format.PROBE},

View File

@ -6,15 +6,15 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var aacFrameFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.ADTS_FRAME,
Description: "Audio Data Transport Stream frame",
DecodeFn: adtsFrameDecoder,

View File

@ -2,14 +2,14 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var annexBAVCNALUFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AVC_ANNEXB,
Description: "H.264/AVC Annex B",
DecodeFn: func(d *decode.D, in any) any {

View File

@ -4,14 +4,14 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var avcNALUFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AVC_AU,
Description: "H.264/AVC Access Unit",
DecodeFn: avcAUDecode,

View File

@ -7,15 +7,15 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var avcDCRNALFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AVC_DCR,
Description: "H.264/AVC Decoder Configuration Record",
DecodeFn: avcDcrDecode,

View File

@ -4,10 +4,10 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/internal/mathextra"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -16,7 +16,7 @@ var avcPPSFormat decode.Group
var avcSEIFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AVC_NALU,
Description: "H.264/AVC Network Access Layer Unit",
DecodeFn: avcNALUDecode,
@ -102,7 +102,7 @@ func avcNALUDecode(d *decode.D, in any) any {
d.FieldBool("forbidden_zero_bit")
d.FieldU2("nal_ref_idc")
nalType := d.FieldU5("nal_unit_type", avcNALNames)
unescapedBR := d.NewBitBufFromReader(decode.NALUnescapeReader{Reader: bitio.NewIOReader(d.BitBufRange(d.Pos(), d.BitsLeft()))})
unescapedBR := d.NewBitBufFromReader(nalUnescapeReader{Reader: bitio.NewIOReader(d.BitBufRange(d.Pos(), d.BitsLeft()))})
switch nalType {
case avcNALCodedSliceNonIDR,

View File

@ -2,13 +2,13 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AVC_PPS,
Description: "H.264/AVC Picture Parameter Set",
DecodeFn: avcPPSDecode,

View File

@ -2,13 +2,13 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AVC_SEI,
Description: "H.264/AVC Supplemental Enhancement Information",
DecodeFn: avcSEIDecode,

View File

@ -2,13 +2,13 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AVC_SPS,
Description: "H.264/AVC Sequence Parameter Set",
DecodeFn: avcSPSDecode,

View File

@ -2,14 +2,14 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var annexBHEVCNALUFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.HEVC_ANNEXB,
Description: "H.265/HEVC Annex B",
DecodeFn: func(d *decode.D, in any) any {

View File

@ -2,14 +2,14 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var hevcAUNALFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.HEVC_AU,
Description: "H.265/HEVC Access Unit",
DecodeFn: hevcAUDecode,

View File

@ -2,15 +2,15 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var hevcDCRNALFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.HEVC_DCR,
Description: "H.265/HEVC Decoder Configuration Record",
DecodeFn: hevcDcrDecode,

View File

@ -2,9 +2,9 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -13,7 +13,7 @@ var hevcPPSFormat decode.Group
var hevcSPSFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.HEVC_NALU,
Description: "H.265/HEVC Network Access Layer Unit",
DecodeFn: hevcNALUDecode,
@ -87,7 +87,7 @@ func hevcNALUDecode(d *decode.D, in any) any {
nalType := d.FieldU6("nal_unit_type", hevcNALNames)
d.FieldU6("nuh_layer_id")
d.FieldU3("nuh_temporal_id_plus1")
unescapedBR := d.NewBitBufFromReader(decode.NALUnescapeReader{Reader: bitio.NewIOReader(d.BitBufRange(d.Pos(), d.BitsLeft()))})
unescapedBR := d.NewBitBufFromReader(nalUnescapeReader{Reader: bitio.NewIOReader(d.BitBufRange(d.Pos(), d.BitsLeft()))})
switch nalType {
case hevcNALNUTVPS:

View File

@ -4,12 +4,12 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.HEVC_PPS,
Description: "H.265/HEVC Picture Parameter Set",
DecodeFn: hevcPPSDecode,

View File

@ -4,12 +4,12 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.HEVC_SPS,
Description: "H.265/HEVC Sequence Parameter Set",
DecodeFn: hevcSPSDecode,

View File

@ -4,12 +4,12 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.HEVC_VPS,
Description: "H.265/HEVC Video Parameter Set",
DecodeFn: hevcVPSDecode,

View File

@ -14,16 +14,16 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/checksum"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var xingHeader decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MP3_FRAME,
Description: "MPEG audio layer 3 frame",
DecodeFn: frameDecode,

View File

@ -4,13 +4,13 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MPEG_ASC,
Description: "MPEG-4 Audio Specific Config",
DecodeFn: ascDecoder,

View File

@ -5,8 +5,8 @@ import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -14,7 +14,7 @@ var mpegASCFormat decode.Group
var vorbisPacketFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MPEG_ES,
Description: "MPEG Elementary Stream",
DecodeFn: esDecode,

View File

@ -6,16 +6,16 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var pesPacketFormat decode.Group
var spuFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MPEG_PES,
Description: "MPEG Packetized elementary stream",
DecodeFn: pesDecode,

View File

@ -5,13 +5,13 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MPEG_PES_PACKET,
Description: "MPEG Packetized elementary stream packet",
DecodeFn: pesPacketDecode,

View File

@ -9,13 +9,13 @@ import (
"strings"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MPEG_SPU,
Description: "Sub Picture Unit (DVD subtitle)",
DecodeFn: spuDecode,

View File

@ -2,13 +2,13 @@ package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MPEG_TS,
ProbeOrder: 10, // make sure to be after gif, both start with 0x47
Description: "MPEG Transport Stream",

View File

@ -1,9 +1,48 @@
package mpeg
import (
"bytes"
"io"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
interp.RegisterFunc0("nal_unescape", makeBinaryTransformFn(func(r io.Reader) (io.Reader, error) {
return &nalUnescapeReader{Reader: r}, nil
}))
}
// transform to binary using fn
func makeBinaryTransformFn(fn func(r io.Reader) (io.Reader, error)) func(i *interp.Interp, c any) any {
return func(i *interp.Interp, c any) any {
inBR, err := interp.ToBitReader(c)
if err != nil {
return err
}
r, err := fn(bitio.NewIOReader(inBR))
if err != nil {
return err
}
outBuf := &bytes.Buffer{}
if _, err := io.Copy(outBuf, r); err != nil {
return err
}
outBR := bitio.NewBitReader(outBuf.Bytes(), -1)
bb, err := interp.NewBinaryFromBitReader(outBR, 8, 0)
if err != nil {
return err
}
return bb
}
}
func decodeEscapeValueFn(add int, b1 int, b2 int, b3 int) func(d *decode.D) uint64 {
return func(d *decode.D) uint64 {
n1 := d.U(b1)
@ -43,3 +82,31 @@ func decodeEscapeValueAddFn(b1 int, b2 int, b3 int) func(d *decode.D) uint64 {
func decodeEscapeValueCarryFn(b1 int, b2 int, b3 int) func(d *decode.D) uint64 {
return decodeEscapeValueFn(1, b1, b2, b3)
}
// TODO: move?
// TODO: make generic replace reader? share with id3v2 unsync?
type nalUnescapeReader struct {
io.Reader
lastTwoZeros [2]bool
}
func (r nalUnescapeReader) Read(p []byte) (n int, err error) {
n, err = r.Reader.Read(p)
ni := 0
for i, b := range p[0:n] {
if r.lastTwoZeros[0] && r.lastTwoZeros[1] && b == 0x03 {
n--
r.lastTwoZeros[0] = false
r.lastTwoZeros[1] = false
continue
} else {
r.lastTwoZeros[1] = r.lastTwoZeros[0]
r.lastTwoZeros[0] = b == 0
}
p[ni] = p[i]
ni++
}
return n, err
}

View File

@ -8,8 +8,8 @@ import (
"embed"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -17,7 +17,7 @@ import (
var msgPackFS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.MSGPACK,
Description: "MessagePack",
DecodeFn: decodeMsgPack,

View File

@ -7,9 +7,9 @@ import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var oggPageFormat decode.Group
@ -19,7 +19,7 @@ var flacMetadatablockFormat decode.Group
var flacFrameFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.OGG,
Description: "OGG file",
Groups: []string{format.PROBE},

View File

@ -4,15 +4,15 @@ import (
"bytes"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/checksum"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.OGG_PAGE,
Description: "OGG page",
DecodeFn: pageDecode,

View File

@ -6,14 +6,14 @@ import (
"bytes"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var vorbisComment decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.OPUS_PACKET,
Description: "Opus packet",
DecodeFn: opusDecode,

View File

@ -6,8 +6,8 @@ package pcap
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/inet/flowsdecoder"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -26,7 +26,7 @@ var endianMap = scalar.UToSymStr{
}
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.PCAP,
Description: "PCAP packet capture",
Groups: []string{format.PROBE},

View File

@ -8,8 +8,8 @@ import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/inet/flowsdecoder"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -18,7 +18,7 @@ var pcapngTCPStreamFormat decode.Group
var pcapngIPvPacket4Format decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.PCAPNG,
Description: "PCAPNG packet capture",
RootArray: true,

View File

@ -9,9 +9,9 @@ import (
"hash/crc32"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -19,7 +19,7 @@ var iccProfileFormat decode.Group
var exifFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.PNG,
Description: "Portable Network Graphics file",
Groups: []string{format.PROBE, format.IMAGE},

View File

@ -6,9 +6,9 @@ import (
"embed"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/internal/mathextra"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -16,7 +16,7 @@ import (
var protobufFS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.PROTOBUF,
Description: "Protobuf",
DecodeFn: protobufDecode,

View File

@ -4,15 +4,15 @@ package protobuf
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var widevineProtoBufFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.PROTOBUF_WIDEVINE,
Description: "Widevine protobuf",
DecodeFn: widevineDecode,

View File

@ -2,12 +2,12 @@ package raw
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.RAW,
Description: "Raw bits",
DecodeFn: func(d *decode.D, in any) any { return nil },

View File

@ -1,13 +0,0 @@
package registry
import (
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/registry"
)
// Default global registry that all builtin formats register with
var Default = registry.New()
func MustRegister(format decode.Format) {
Default.MustRegister(format)
}

View File

@ -4,13 +4,13 @@ package rtmp
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.AMF0,
Description: "Action Message Format 0",
DecodeFn: amf0Decode,

View File

@ -12,9 +12,9 @@ import (
"embed"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -25,7 +25,7 @@ var rtmpMpegASCFormat decode.Group
var rtmpFS embed.FS
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.RTMP,
Description: "Real-Time Messaging Protocol",
Groups: []string{

View File

@ -7,15 +7,15 @@ import (
"bytes"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var probeFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.TAR,
Description: "Tar archive",
Groups: []string{format.PROBE},

View File

@ -5,14 +5,14 @@ package tiff
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
// currently just a alias for tiff
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.EXIF,
Description: "Exchangeable Image File Format",
Groups: []string{},

View File

@ -4,15 +4,15 @@ package tiff
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var tiffIccProfile decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.TIFF,
Description: "Tag Image File Format",
Groups: []string{format.PROBE, format.IMAGE},

View File

@ -6,14 +6,14 @@ import (
"strings"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var flacPicture decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.VORBIS_COMMENT,
Description: "Vorbis comment",
DecodeFn: commentDecode,

View File

@ -6,15 +6,15 @@ package vorbis
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
var vorbisComment decode.Group
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.VORBIS_PACKET,
Description: "Vorbis packet",
DecodeFn: vorbisDecode,

View File

@ -4,15 +4,15 @@ package vpx
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
// TODO: vpx frame?
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.VP8_FRAME,
Description: "VP8 frame",
DecodeFn: vp8Decode,

View File

@ -4,12 +4,12 @@ package vpx
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.VP9_CFM,
Description: "VP9 Codec Feature Metadata",
DecodeFn: vp9CFMDecode,

View File

@ -4,8 +4,8 @@ package vpx
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
@ -56,7 +56,7 @@ var vp9ProfilesMap = scalar.UToDescription{
}
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.VP9_FRAME,
Description: "VP9 frame",
DecodeFn: vp9Decode,

View File

@ -4,12 +4,12 @@ package vpx
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
func init() {
registry.MustRegister(decode.Format{
interp.RegisterFormat(decode.Format{
Name: format.VPX_CCR,
Description: "VPX Codec Configuration Record",
DecodeFn: vpxCCRDecode,

Some files were not shown because too many files have changed in this diff Show More