-
Notifications
You must be signed in to change notification settings - Fork 69
/
nsdictionary.go
44 lines (34 loc) · 939 Bytes
/
nsdictionary.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
package nskeyedarchiver
import (
"howett.net/plist"
)
type NSDictionary struct {
internal map[string]interface{}
}
func NewNSDictionary(value map[string]interface{}) *NSDictionary {
return &NSDictionary{
internal: value,
}
}
func (ns *NSDictionary) archive(objects []interface{}) []interface{} {
keys := make([]interface{}, 0, len(ns.internal))
objs := make([]interface{}, 0, len(ns.internal))
info := map[string]interface{}{}
objects = append(objects, info)
for k, v := range ns.internal {
uid := plist.UID(len(objects))
keys = append(keys, uid)
objects = append(objects, k)
objects, uid = archive(objects, v)
objs = append(objs, uid)
}
info["NS.keys"] = keys
info["NS.objects"] = objs
info["$class"] = plist.UID(len(objects))
cls := map[string]interface{}{
"$classname": "NSDictionary",
"$classes": []interface{}{"NSDictionary", "NSObject"},
}
objects = append(objects, cls)
return objects
}