v2ray-core/common/net/packet.go

60 lines
982 B
Go
Raw Normal View History

package net
type Packet interface {
Destination() Destination
Chunk() []byte // First chunk of this commnunication
MoreChunks() bool
}
func NewTCPPacket(dest Destination) *TCPPacket {
return &TCPPacket{
basePacket: basePacket{destination: dest},
}
}
2015-09-28 14:57:43 +02:00
func NewUDPPacket(dest Destination, data []byte, id uint16) *UDPPacket {
return &UDPPacket{
basePacket: basePacket{destination: dest},
data: data,
2015-09-28 14:57:43 +02:00
id: id,
}
}
type basePacket struct {
destination Destination
}
func (base basePacket) Destination() Destination {
return base.destination
}
type TCPPacket struct {
basePacket
}
func (packet *TCPPacket) Chunk() []byte {
return nil
}
func (packet *TCPPacket) MoreChunks() bool {
return true
}
type UDPPacket struct {
basePacket
data []byte
2015-09-28 14:57:43 +02:00
id uint16
}
func (packet *UDPPacket) ID() uint16 {
return packet.id
}
func (packet *UDPPacket) Chunk() []byte {
return packet.data
}
func (packet *UDPPacket) MoreChunks() bool {
return false
}