1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-19 02:16:11 -04:00
v2fly/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 08:46:12 -04: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 08:46:12 -04:00
// NewPacket creates a new Packet with given destination and payload.
func NewPacket(dest Destination, firstChunk *alloc.Buffer, moreChunks bool) Packet {
2015-10-02 09:32:26 -04:00
return &packetImpl{
dest: dest,
data: firstChunk,
moreData: moreChunks,
}
}
2015-10-02 09:32:26 -04:00
type packetImpl struct {
dest Destination
data *alloc.Buffer
2015-10-02 09:32:26 -04:00
moreData bool
2015-09-28 08:57:43 -04:00
}
2015-10-02 09:32:26 -04:00
func (packet *packetImpl) Destination() Destination {
return packet.dest
}
func (packet *packetImpl) Chunk() *alloc.Buffer {
return packet.data
}
2015-10-02 09:32:26 -04:00
func (packet *packetImpl) MoreChunks() bool {
return packet.moreData
}