1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 05:13:30 +03:00
fq/format/flac/flac_metadatablocks.go
Mattias Wadman 8e0dde03d0 decode: Support multiple format args and some rename and refactor
This will allow passing both cli options and format options to sub decoder.
Ex: pass keylog option to a tls decoder when decoding a pcap.
Ex: pass decode options to a format inside a http body inside a pcap.

Add ArgAs method to lookup argument based on type. This also makes the format
decode function have same signature as sub decoders in the decode API.

This change decode.Format a bit:
DecodeFn is now just func(d *D) any
DecodeInArg renamed to DefaultInArg
2023-02-18 21:38:51 +01:00

45 lines
1.1 KiB
Go

package flac
import (
"fmt"
"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var flacMetadatablockFormat decode.Group
func init() {
interp.RegisterFormat(decode.Format{
Name: format.FLAC_METADATABLOCKS,
Description: "FLAC metadatablocks",
DecodeFn: metadatablocksDecode,
RootArray: true,
RootName: "metadatablocks",
Dependencies: []decode.Dependency{
{Names: []string{format.FLAC_METADATABLOCK}, Group: &flacMetadatablockFormat},
},
})
}
func metadatablocksDecode(d *decode.D) any {
flacMetadatablocksOut := format.FlacMetadatablocksOut{}
isLastBlock := false
for !isLastBlock {
_, v := d.FieldFormat("metadatablock", flacMetadatablockFormat, nil)
flacMetadatablockOut, ok := v.(format.FlacMetadatablockOut)
if !ok {
panic(fmt.Sprintf("expected FlacMetadatablocksOut, got %#+v", flacMetadatablockOut))
}
isLastBlock = flacMetadatablockOut.IsLastBlock
if flacMetadatablockOut.HasStreamInfo {
flacMetadatablocksOut.HasStreamInfo = true
flacMetadatablocksOut.StreamInfo = flacMetadatablockOut.StreamInfo
}
}
return flacMetadatablocksOut
}