-
Notifications
You must be signed in to change notification settings - Fork 52
/
ufid_frame.go
41 lines (32 loc) · 896 Bytes
/
ufid_frame.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package id3v2
import "io"
// UFIDFrame is used for "Unique file identifier"
type UFIDFrame struct {
OwnerIdentifier string
Identifier []byte
}
func (ufid UFIDFrame) UniqueIdentifier() string {
return ufid.OwnerIdentifier
}
func (ufid UFIDFrame) Size() int {
return encodedSize(ufid.OwnerIdentifier, EncodingISO) + len(EncodingISO.TerminationBytes) + len(ufid.Identifier)
}
func (ufid UFIDFrame) WriteTo(w io.Writer) (n int64, err error) {
return useBufWriter(w, func(bw *bufWriter) {
bw.WriteString(ufid.OwnerIdentifier)
bw.Write(EncodingISO.TerminationBytes)
bw.Write(ufid.Identifier)
})
}
func parseUFIDFrame(br *bufReader) (Framer, error) {
owner := br.ReadText(EncodingISO)
ident := br.ReadAll()
if br.Err() != nil {
return nil, br.Err()
}
ufid := UFIDFrame{
OwnerIdentifier: decodeText(owner, EncodingISO),
Identifier: ident,
}
return ufid, nil
}