2015-09-22 08:45:03 -04:00
|
|
|
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 15:32:07 -04:00
|
|
|
func NewUDPPacket(dest Destination, data []byte, token uint16) *UDPPacket {
|
2015-09-22 08:45:03 -04:00
|
|
|
return &UDPPacket{
|
|
|
|
basePacket: basePacket{destination: dest},
|
|
|
|
data: data,
|
2015-09-28 15:32:07 -04:00
|
|
|
token: token,
|
2015-09-22 08:45:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2015-09-28 15:32:07 -04:00
|
|
|
data []byte
|
|
|
|
token uint16
|
2015-09-28 08:57:43 -04:00
|
|
|
}
|
|
|
|
|
2015-09-28 15:32:07 -04:00
|
|
|
func (packet *UDPPacket) Token() uint16 {
|
|
|
|
return packet.token
|
2015-09-22 08:45:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (packet *UDPPacket) Chunk() []byte {
|
|
|
|
return packet.data
|
|
|
|
}
|
|
|
|
|
|
|
|
func (packet *UDPPacket) MoreChunks() bool {
|
|
|
|
return false
|
|
|
|
}
|