-
Notifications
You must be signed in to change notification settings - Fork 52
/
user_defined_text_frame.go
52 lines (41 loc) · 1.33 KB
/
user_defined_text_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
42
43
44
45
46
47
48
49
50
51
52
package id3v2
import "io"
// UserDefinedTextFrame is used to work with TXXX frames.
// There can be many UserDefinedTextFrames but the Description fields need to be unique.
type UserDefinedTextFrame struct {
Encoding Encoding
Description string
Value string
}
func (udtf UserDefinedTextFrame) Size() int {
return 1 + encodedSize(udtf.Description, udtf.Encoding) + len(udtf.Encoding.TerminationBytes) + encodedSize(udtf.Value, udtf.Encoding)
}
func (udtf UserDefinedTextFrame) UniqueIdentifier() string {
return udtf.Description
}
func (udtf UserDefinedTextFrame) WriteTo(w io.Writer) (n int64, err error) {
return useBufWriter(w, func(bw *bufWriter) {
bw.WriteByte(udtf.Encoding.Key)
bw.EncodeAndWriteText(udtf.Description, udtf.Encoding)
bw.Write(udtf.Encoding.TerminationBytes)
bw.EncodeAndWriteText(udtf.Value, udtf.Encoding)
})
}
func parseUserDefinedTextFrame(br *bufReader) (Framer, error) {
encoding := getEncoding(br.ReadByte())
description := br.ReadText(encoding)
if br.Err() != nil {
return nil, br.Err()
}
value := getBytesBuffer()
defer putBytesBuffer(value)
if _, err := value.ReadFrom(br); err != nil {
return nil, err
}
udtf := UserDefinedTextFrame{
Encoding: encoding,
Description: decodeText(description, encoding),
Value: decodeText(value.Bytes(), encoding),
}
return udtf, nil
}