mirror of
				https://github.com/v2fly/v2ray-core.git
				synced 2025-11-03 19:29:22 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			819 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			819 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package net
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/v2ray/v2ray-core/common/alloc"
 | 
						|
)
 | 
						|
 | 
						|
// 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
 | 
						|
}
 | 
						|
 | 
						|
// NewPacket creates a new Packet with given destination and payload.
 | 
						|
func NewPacket(dest Destination, firstChunk *alloc.Buffer, moreChunks bool) Packet {
 | 
						|
	return &packetImpl{
 | 
						|
		dest:     dest,
 | 
						|
		data:     firstChunk,
 | 
						|
		moreData: moreChunks,
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
type packetImpl struct {
 | 
						|
	dest     Destination
 | 
						|
	data     *alloc.Buffer
 | 
						|
	moreData bool
 | 
						|
}
 | 
						|
 | 
						|
func (packet *packetImpl) Destination() Destination {
 | 
						|
	return packet.dest
 | 
						|
}
 | 
						|
 | 
						|
func (packet *packetImpl) Chunk() *alloc.Buffer {
 | 
						|
	return packet.data
 | 
						|
}
 | 
						|
 | 
						|
func (packet *packetImpl) MoreChunks() bool {
 | 
						|
	return packet.moreData
 | 
						|
}
 |