-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket.go
78 lines (67 loc) · 1.41 KB
/
packet.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
package siop
import "strconv"
type (
// PacketType indicates type of socket.io Packet
PacketType byte
Packet struct {
Type PacketType
Nsp string
Data any
ID *uint64
Attachments int
}
)
const (
Connect PacketType = iota
Disconnect
Event
Ack
ConnectError
BinaryEvent
BinaryAck
)
const (
StrConnect = "CONNECT"
StrDisconnect = "DISCONNECT"
StrEvent = "EVENT"
StrAck = "ACK"
StrConnectError = "CONNECT_ERROR"
StrBinaryEvent = "BINARY_EVENT"
StrBinaryAck = "BINARY_ACK"
)
var (
PacketTypeToString = map[PacketType]string{
Connect: StrConnect,
Disconnect: StrDisconnect,
Event: StrEvent,
Ack: StrAck,
ConnectError: StrConnectError,
BinaryEvent: StrBinaryEvent,
BinaryAck: StrBinaryAck,
}
StringToPacketType = map[string]PacketType{
StrConnect: Connect,
StrDisconnect: Disconnect,
StrEvent: Event,
StrAck: Ack,
StrConnectError: ConnectError,
StrBinaryEvent: BinaryEvent,
StrBinaryAck: BinaryAck,
}
)
// String returns string representation of a PacketType
func (p PacketType) String() string {
return PacketTypeToString[p]
}
func (p PacketType) Int() int {
return int(p)
}
func (p PacketType) Encode() string {
return strconv.Itoa(p.Int())
}
func (p PacketType) Bytes() []byte {
return []byte(p.Encode())
}
func (p Packet) Encode() []any {
return Encode(p)
}