-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdaap.go
More file actions
63 lines (54 loc) · 1.22 KB
/
Copy pathdaap.go
File metadata and controls
63 lines (54 loc) · 1.22 KB
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
53
54
55
56
57
58
59
60
61
62
63
package airplay
import (
"fmt"
)
var (
DAAPGroups = map[string]bool{
"cmst": true,
"mlog": true,
"agal": true,
"mlcl": true,
"mshl": true,
"mlit": true,
"abro": true,
"abar": true,
"apso": true,
"caci": true,
"avdb": true,
"cmgt": true,
"aply": true,
"adbs": true,
"cmpa": true,
}
)
func DAAPParse(buffer []byte) (tags map[string]interface{}) {
tags = make(map[string]interface{}, 100) // TODO: Make this a better capacity ;-)
length := len(buffer)
offset := 0
for offset < length {
tag := string(buffer[offset : offset+4])
offset += 4
size := int(buffer[offset])<<24 | int(buffer[offset+1])<<16 | int(buffer[offset+2])<<8 | int(buffer[offset+3])
offset += 4
if DAAPGroups[tag] {
data := DAAPParse(buffer[offset : offset+size])
tags[tag] = data
} else {
data := string(buffer[offset : offset+size])
tags[tag] = data
}
offset += size
}
return
}
func DAAPPrint(tags map[string]interface{}, indent string) (out string) {
for tag := range tags {
if DAAPGroups[tag] {
out += fmt.Sprintf("%s%s:\n", indent, tag)
out += DAAPPrint(tags[tag].(map[string]interface{}), indent+"\t")
} else {
out += fmt.Sprintf("%s%s: %s\n", indent, tag, tags[tag])
}
}
return
}