v2ray-core/common/net/packet.go

40 lines
819 B
Go
Raw Normal View History

package net
import (
"github.com/v2ray/v2ray-core/common/alloc"
)
2015-10-11 12:46:12 +00:00
// Packet is a network packet to be sent to destination.
type Packet interface {
Destination() Destination
Chunk() *alloc.Buffer // First chunk of this commnunication
MoreChunks() bool
}
2015-10-11 12:46:12 +00:00
// NewPacket creates a new Packet with given destination and payload.
func NewPacket(dest Destination, firstChunk *alloc.Buffer, moreChunks bool) Packet {
2015-10-02 13:32:26 +00:00
return &packetImpl{
dest: dest,
data: firstChunk,
moreData: moreChunks,
}
}
2015-10-02 13:32:26 +00:00
type packetImpl struct {
dest Destination
data *alloc.Buffer
2015-10-02 13:32:26 +00:00
moreData bool
2015-09-28 12:57:43 +00:00
}
2015-10-02 13:32:26 +00:00
func (packet *packetImpl) Destination() Destination {
return packet.dest
}
func (packet *packetImpl) Chunk() *alloc.Buffer {
return packet.data
}
2015-10-02 13:32:26 +00:00
func (packet *packetImpl) MoreChunks() bool {
return packet.moreData
}