1
1
mirror of https://github.com/wader/fq.git synced 2024-11-28 11:42:50 +03:00
fq/format/flac/flac_metadatablocks.go

45 lines
1.2 KiB
Go
Raw Normal View History

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