forked from Mrs4s/MiraiGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
t511.go
64 lines (62 loc) · 1.24 KB
/
t511.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
53
54
55
56
57
58
59
60
61
62
63
64
package tlv
import (
"github.com/Sclock/MiraiGo/binary"
)
func T511(domains []string) []byte {
nonnildomains := domains
// 目前的所有调用均无 ""
/*
hasnil := false
for _, d := range domains {
if d == "" {
hasnil = true
break
}
}
if hasnil {
nonnildomains = nonnildomains[:0]
for _, d := range domains {
if d != "" {
nonnildomains = append(nonnildomains, d)
}
}
}
*/
return binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(0x511)
pos := w.FillUInt16()
w.WriteUInt16(uint16(len(nonnildomains)))
for _, d := range nonnildomains {
// 目前的所有调用均不会出现 ()
// indexOf := strings.Index(d, "(")
// indexOf2 := strings.Index(d, ")")
// if indexOf != 0 || indexOf2 <= 0 {
w.WriteByte(0x01)
w.WriteStringShort(d)
/* } else {
var b byte
var z bool
i, err := strconv.Atoi(d[indexOf+1 : indexOf2])
if err == nil {
z2 := (1048576 & i) > 0
if (i & 134217728) > 0 {
z = true
} else {
z = false
}
if z2 {
b = 1
} else {
b = 0
}
if z {
b |= 2
}
w.WriteByte(b)
w.WriteBytesShort([]byte(d[indexOf2+1:]))
}
}*/
}
w.WriteUInt16At(pos, uint16(w.Len()-4))
})
}