-
Notifications
You must be signed in to change notification settings - Fork 2
/
type.go
42 lines (36 loc) · 1.06 KB
/
type.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
package parser
import (
"github.com/zishang520/engine.io-go-parser/packet"
"github.com/zishang520/engine.io-go-parser/types"
)
type Parser interface {
Protocol() int
EncodePacket(*packet.Packet, bool, ...bool) (types.BufferInterface, error)
DecodePacket(types.BufferInterface, ...bool) (*packet.Packet, error)
EncodePayload([]*packet.Packet, ...bool) (types.BufferInterface, error)
DecodePayload(types.BufferInterface) ([]*packet.Packet, error)
}
const SEPARATOR byte = 0x1E
// Packet types.
var (
PACKET_TYPES map[packet.Type]byte = map[packet.Type]byte{
packet.OPEN: '0',
packet.CLOSE: '1',
packet.PING: '2',
packet.PONG: '3',
packet.MESSAGE: '4',
packet.UPGRADE: '5',
packet.NOOP: '6',
}
PACKET_TYPES_REVERSE map[byte]packet.Type = map[byte]packet.Type{
'0': packet.OPEN,
'1': packet.CLOSE,
'2': packet.PING,
'3': packet.PONG,
'4': packet.MESSAGE,
'5': packet.UPGRADE,
'6': packet.NOOP,
}
// Premade error packet.
ERROR_PACKET = &packet.Packet{Type: packet.ERROR, Data: types.NewStringBufferString(`parser error`)}
)