1
1
mirror of https://github.com/wader/fq.git synced 2024-12-29 00:22:38 +03:00
fq/format/id3/id3v11.go
Mattias Wadman 2fc0a71a47 decode: Refactor scalar usage
Move scalar into own package.
Split scalar code into decode related scalar code (that reads etc) and
scalar code that just transform the scalar value.
Use a scalar.Mapper interface instead of just a function.
Make mappers, assert and validat impement the interface.
2021-12-02 17:39:26 +01:00

37 lines
739 B
Go

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/scalar"
)
func init() {
registry.MustRegister(decode.Format{
Name: format.ID3V11,
Description: "ID3v1.1 metadata",
DecodeFn: id3v11Decode,
})
}
func id3v11Decode(d *decode.D, in interface{}) interface{} {
d.AssertAtLeastBitsLeft(128 * 8)
d.FieldUTF8("magic", 4, d.AssertStr("TAG+"))
d.FieldUTF8("title", 60)
d.FieldUTF8("artist", 60)
d.FieldUTF8("album", 60)
d.FieldU8("speed", scalar.UToSymStr{
0: "unset",
1: "slow",
2: "medium",
3: "fast",
4: "hardcore",
})
d.FieldUTF8("genre", 30)
d.FieldUTF8("start", 6)
d.FieldUTF8("stop", 6)
return nil
}