Skip to content

Commit

Permalink
update: Add buffer test files and optimize code to improve readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
zishang520 committed Oct 21, 2023
1 parent c282647 commit e0e0b7a
Show file tree
Hide file tree
Showing 3 changed files with 746 additions and 14 deletions.
26 changes: 14 additions & 12 deletions packet/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ import (
"github.com/zishang520/engine.io-go-parser/types"
)

type Type string
type (
Type string

Options struct {
Compress bool `json:"compress" mapstructure:"compress" msgpack:"compress"`
}

Packet struct {
Type Type `json:"type" mapstructure:"type" msgpack:"type"`
Data io.Reader `json:"data,omitempty" mapstructure:"data,omitempty" msgpack:"data,omitempty"`
Options *Options `json:"options,omitempty" mapstructure:"options,omitempty" msgpack:"options,omitempty"`
WsPreEncoded types.BufferInterface `json:"wsPreEncoded,omitempty" mapstructure:"wsPreEncoded,omitempty" msgpack:"wsPreEncoded,omitempty"`
}
)

// Packet types.
const (
Expand All @@ -19,14 +32,3 @@ const (
NOOP Type = "noop"
ERROR Type = "error"
)

type Options struct {
Compress bool `json:"compress" mapstructure:"compress" msgpack:"compress"`
}

type Packet struct {
Type Type `json:"type" mapstructure:"type" msgpack:"type"`
Data io.Reader `json:"data,omitempty" mapstructure:"data,omitempty" msgpack:"data,omitempty"`
Options *Options `json:"options,omitempty" mapstructure:"options,omitempty" msgpack:"options,omitempty"`
WsPreEncoded types.BufferInterface `json:"wsPreEncoded,omitempty" mapstructure:"wsPreEncoded,omitempty" msgpack:"wsPreEncoded,omitempty"`
}
4 changes: 2 additions & 2 deletions parser/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Parser interface {
DecodePayload(types.BufferInterface) ([]*packet.Packet, error)
}

const SEPARATOR byte = 0x1E

// Packet types.
var (
PACKET_TYPES map[packet.Type]byte = map[packet.Type]byte{
Expand All @@ -38,5 +40,3 @@ var (
// Premade error packet.
ERROR_PACKET = &packet.Packet{Type: packet.ERROR, Data: types.NewStringBufferString(`parser error`)}
)

const SEPARATOR = byte(0x1E)
Loading

0 comments on commit e0e0b7a

Please sign in to comment.