packet.go 819 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package net
  2. import (
  3. "github.com/v2ray/v2ray-core/common/alloc"
  4. )
  5. // Packet is a network packet to be sent to destination.
  6. type Packet interface {
  7. Destination() Destination
  8. Chunk() *alloc.Buffer // First chunk of this commnunication
  9. MoreChunks() bool
  10. }
  11. // NewPacket creates a new Packet with given destination and payload.
  12. func NewPacket(dest Destination, firstChunk *alloc.Buffer, moreChunks bool) Packet {
  13. return &packetImpl{
  14. dest: dest,
  15. data: firstChunk,
  16. moreData: moreChunks,
  17. }
  18. }
  19. type packetImpl struct {
  20. dest Destination
  21. data *alloc.Buffer
  22. moreData bool
  23. }
  24. func (packet *packetImpl) Destination() Destination {
  25. return packet.dest
  26. }
  27. func (packet *packetImpl) Chunk() *alloc.Buffer {
  28. return packet.data
  29. }
  30. func (packet *packetImpl) MoreChunks() bool {
  31. return packet.moreData
  32. }