packet.go 608 B

123456789101112131415161718192021222324252627282930313233
  1. package net
  2. type Packet interface {
  3. Destination() Destination
  4. Chunk() []byte // First chunk of this commnunication
  5. MoreChunks() bool
  6. }
  7. func NewPacket(dest Destination, firstChunk []byte, moreChunks bool) Packet {
  8. return &packetImpl{
  9. dest: dest,
  10. data: firstChunk,
  11. moreData: moreChunks,
  12. }
  13. }
  14. type packetImpl struct {
  15. dest Destination
  16. data []byte
  17. moreData bool
  18. }
  19. func (packet *packetImpl) Destination() Destination {
  20. return packet.dest
  21. }
  22. func (packet *packetImpl) Chunk() []byte {
  23. return packet.data
  24. }
  25. func (packet *packetImpl) MoreChunks() bool {
  26. return packet.moreData
  27. }