packet.go 692 B

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