-
Notifications
You must be signed in to change notification settings - Fork 205
/
common.go
36 lines (32 loc) · 1.2 KB
/
common.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
/*--------------------------------------------------------*\
| |
| hprose |
| |
| Official WebSite: https://hprose.com |
| |
| rpc/websocket/common.go |
| |
| LastModified: Mar 18, 2022 |
| Author: Ma Bingyao <andot@hprose.com> |
| |
\*________________________________________________________*/
package websocket
type data struct {
Index int
Body []byte
Error error
}
func makeHeader(index int) (header [4]byte) {
header[3] = byte(index & 0xff)
header[2] = byte(index >> 8 & 0xff)
header[1] = byte(index >> 16 & 0xff)
header[0] = byte(index >> 24 & 0xff)
return
}
func parseHeader(header []byte) (index int, ok bool) {
index = int(header[3]) | int(header[2])<<8 | int(header[1])<<16 | int(header[0])<<24
if ok = (header[0]&0x80 == 0); !ok {
index &= 0x7fffffff
}
return
}