-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbinary_data_test.go
211 lines (193 loc) · 6.67 KB
/
binary_data_test.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package xivnet_test
import (
"time"
"github.com/ff14wed/xivnet/v3"
)
var zlibPacket = []byte{
0x52, 0x52, 0xa0, 0x41, 0xff, 0x5d, 0x46, 0xe2,
0x7f, 0x2a, 0x64, 0x4d, 0x7b, 0x99, 0xc4, 0x75, // Preamble
0xe6, 0xf6, 0x93, 0xda, 0x59, 0x01, 0x00, 0x00, // Time
0x94, 0x00, 0x00, 0x00, // Length
0x00, 0x00, // ConnectionType
0x04, 0x00, // Count
0x01, 0x01, // Reserved1 and Compression
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved2 and Reserved3
// Zlib compressed block
0x78, 0x9c, 0xb2, 0x60, 0x60, 0x60, 0x10, 0x3d, 0x1b, 0xcd, 0x0e, 0xc2, 0xcc,
0x0c, 0x0c, 0x0c, 0x22, 0x0c, 0x4e, 0x8c, 0x0c, 0x0c, 0x4a, 0x0c, 0xf6, 0x0f,
0x3a, 0x23, 0x18, 0xc0, 0xe0, 0xec, 0x43, 0x10, 0xc9, 0x08, 0xc5, 0x20, 0xa0,
0xc0, 0xc0, 0xc0, 0x80, 0xa9, 0x2f, 0x0c, 0x45, 0x5f, 0xfb, 0x0f, 0x27, 0xb0,
0x7a, 0x5f, 0x06, 0x26, 0x06, 0x46, 0x86, 0x7c, 0x06, 0x18, 0x30, 0xc0, 0xd0,
0x27, 0x8d, 0xa2, 0x8f, 0x09, 0x61, 0x0d, 0x18, 0x78, 0x60, 0xa8, 0xf7, 0xc5,
0x69, 0x0f, 0xdc, 0x71, 0x20, 0xa0, 0x67, 0x64, 0x61, 0x66, 0x60, 0x61, 0x64,
0xc9, 0xc0, 0xc0, 0x20, 0xc0, 0xc0, 0xc0, 0x00, 0x08, 0x00, 0x00, 0xff, 0xff,
0x34, 0x44, 0x1d, 0x27,
}
var jsonZlibFramePreamble string = `"52 52 a0 41 ff 5d 46 e2 7f 2a 64 4d 7b 99 c4 75"`
var jsonZlibBlock0Header string = `{"Length":56,"SubjectID":123456789,"CurrentID":123456789,"Type":3,"Pad1":0,`
var jsonZlibBlock0IPCHeader string = `"Reserved":20,"Opcode":322,"Pad2":0,"ServerID":34,"Time":"2017-01-26T11:40:47Z","Pad3":0`
var jsonZlibBlock0Data string = `"00 00 cd e1 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 20 00 00 00"`
var bytesZlibBlock0 = []byte{
0x38, 0x00, 0x00, 0x00, // Length
0x15, 0xCD, 0x5B, 0x07, // SubjectID
0x15, 0xCD, 0x5B, 0x07, // CurrentID
0x03, 0x00, 0x00, 0x00, // Type and Padding
0x14, 0x00, 0x42, 0x01, // Reserved and Opcode
0x00, 0x00, 0x22, 0x00, // Padding and Route
0x3f, 0xe0, 0x89, 0x58, // Time
0x00, 0x00, 0x00, 0x00, // Pad3
// BlockData
0x00, 0x00, 0xcd, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
}
var expectedZlibFrame = xivnet.Frame{
Preamble: [16]byte{
0x52, 0x52, 0xa0, 0x41, 0xff, 0x5d, 0x46, 0xe2,
0x7f, 0x2a, 0x64, 0x4d, 0x7b, 0x99, 0xc4, 0x75,
},
Time: time.Unix(1485430847, 206000000),
Length: 148,
Count: 4,
Reserved1: 1,
Compression: 1,
Blocks: []*xivnet.Block{
&xivnet.Block{
Length: 56,
SubjectID: 123456789,
CurrentID: 123456789,
Type: xivnet.BlockTypeIPC,
Pad1: 0,
IPCHeader: xivnet.IPCHeader{
Reserved: 0x14,
Opcode: 0x142,
ServerID: 34,
Time: time.Unix(0x5889e03f, 0),
},
Data: xivnet.GenericBlockDataFromBytes([]byte{
0x00, 0x00, 0xcd, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
}),
},
&xivnet.Block{
Length: 56,
SubjectID: 123456789,
CurrentID: 123456789,
Type: xivnet.BlockTypeIPC,
Pad1: 0,
IPCHeader: xivnet.IPCHeader{
Reserved: 0x14,
Opcode: 0x156,
ServerID: 34,
Time: time.Unix(0x5889e03f, 0),
},
Data: xivnet.GenericBlockDataFromBytes([]byte{
0x87, 0xf8, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x02, 0x00,
0x01, 0x00, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}),
},
&xivnet.Block{
Length: 48,
SubjectID: 123456789,
CurrentID: 123456789,
Type: xivnet.BlockTypeIPC,
Pad1: 0,
IPCHeader: xivnet.IPCHeader{
Reserved: 0x14,
Opcode: 0x11b,
ServerID: 34,
Time: time.Unix(0x5889e03f, 0),
},
Data: xivnet.GenericBlockDataFromBytes([]byte{
0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}),
},
&xivnet.Block{
Length: 72,
SubjectID: 123456789,
CurrentID: 123456789,
Type: xivnet.BlockTypeIPC,
Pad1: 0,
IPCHeader: xivnet.IPCHeader{
Reserved: 0x14,
Opcode: 0x14d,
ServerID: 34,
Time: time.Unix(0x5889e03f, 0),
},
Data: xivnet.GenericBlockDataFromBytes([]byte{
0x87, 0xf8, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x2e, 0x32, 0x38, 0x36, 0x30, 0x38, 0x32, 0x39, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00,
}),
},
},
}
var nonZlibPacket = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Preamble
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Time
0x40, 0x00, 0x00, 0x00, // Length
0x00, 0x00, // ConnectionType
0x01, 0x00, // Count
0x00, 0x00, // Reserved1 and Compression
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved2 and Reserved3
// Block
0x18, 0x00, 0x00, 0x00, // Length
0x01, 0x02, 0x03, 0x04, // SubjectID
0x05, 0x06, 0x07, 0x08, // CurrentID
0x08, 0x00, // Type
0x00, 0x00, // Pad1
0x15, 0xCD, 0x5B, 0x07, 0x42, 0xe0, 0x89, 0x58, // Data
}
var expectedNonZlibFrame = xivnet.Frame{
Preamble: [16]byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
},
Time: time.Unix(0, 0),
Length: 64,
Count: 1,
Compression: 0,
Blocks: []*xivnet.Block{
&xivnet.Block{
Length: 24,
SubjectID: 0x04030201,
CurrentID: 0x08070605,
Type: 8,
Data: xivnet.GenericBlockDataFromBytes([]byte{
0x15, 0xCD, 0x5B, 0x07, 0x42, 0xe0, 0x89, 0x58,
}),
},
},
}
var invalidHeaderPacket = []byte{
0x52, 0x52, 0x00, 0x00, 0xff, 0x5d, 0x46, 0xe2, 0x7f, 0x2a, 0x64, 0x4d, 0x7b,
0x99, 0xc4, 0x75, 0xe6, 0xf6, 0x93, 0xda, 0x59, 0x01, 0x00, 0x00, 0x8a, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
}
var zeroBlockPacket = []byte{
0x52, 0x52, 0xa0, 0x41, 0xff, 0x5d, 0x46, 0xe2,
0x7f, 0x2a, 0x64, 0x4d, 0x7b, 0x99, 0xc4, 0x75, // Preamble
0xcf, 0xa1, 0x01, 0x08, 0x61, 0x01, 0x00, 0x00, // Time
0x30, 0x00, 0x00, 0x00, // Length
0x00, 0x00, // ConnectionType
0x00, 0x00, // Count
0x01, 0x01, // Reserved1 and Compression
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved2 and Reserved3
0x78, 0x9c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, // BlockData
}
var invalidBlockPacket = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Preamble
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Time
0x40, 0x00, 0x00, 0x00, // Length
0x00, 0x00, // ConnectionType
0x01, 0x00, // Count
0x00, 0x00, // Reserved1 and Compression
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved2 and Reserved3
// BlockData
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x15, 0xCD, 0x5B, 0x07, 0x42, 0xe0, 0x89, 0x58,
}