func (pb *PacketBuffer) PacketLen() int {
	return pb.BlockBuffer.BlockLen()
}
PacketLen returns the number of packets in the PacketBuffer.
package capture
import (
	"errors"
	"github.com/google/gopacket"
)
var (
	ErrBytesFull = errors.New("buffer out of space for more bytes")
	ErrBlocksFull = errors.New("buffer out of space for more packets")
)
type BlockBuffer struct {
	offsets []int
	data []byte
}
func NewBlockBuffer(maxBlocks, maxBytes int) BlockBuffer {
	return BlockBuffer{
		offsets: make([]int, 0, maxBlocks),
		data:    make([]byte, 0, maxBytes),
	}
}
func (b *BlockBuffer) BytesRemaining() int {
	return cap(b.data) - len(b.data)
}
func (b *BlockBuffer) Block(n int) []byte {
	start := 0
	if n > 0 {
		start = b.offsets[n-1]
	}
	end := b.offsets[n]
	return b.data[start:end:end]
}
func (b *BlockBuffer) BlockLen() int {
	return len(b.offsets)
}
func (b *BlockBuffer) Clear() {
	b.offsets = b.offsets[:0]
	b.data = b.data[:0]
}
func (b *BlockBuffer) Append(data []byte) error {
	if cap(b.offsets) == 0 {
		panic("attempted to Append to uninitialized BlockBuffer")
	}
	if len(b.offsets) >= cap(b.offsets) {
		return ErrBlocksFull
	}
	start := len(b.data)
	end := len(b.data) + len(data)
	if end > cap(b.data) {
		return ErrBytesFull
	}
	b.data = b.data[:end]
	copy(b.data[start:], data)
	b.offsets = b.offsets[:len(b.offsets)+1]
	b.offsets[len(b.offsets)-1] = end
	return nil
}
type PacketBuffer struct {
	BlockBuffer
	cis []gopacket.CaptureInfo
}
func NewPacketBuffer(maxPackets, maxBytes int) *PacketBuffer {
	return &PacketBuffer{
		BlockBuffer: NewBlockBuffer(maxPackets, maxBytes),
		cis:         make([]gopacket.CaptureInfo, maxPackets),
	}
}
func (pb *PacketBuffer) Append(pd PacketData) error {
	err := pb.BlockBuffer.Append(pd.Data)
	if err != nil {
		return err
	}
	pb.cis[len(pb.BlockBuffer.offsets)-1] = pd.Info
	return nil
}
func (pb *PacketBuffer) PacketCap() int {
	return cap(pb.BlockBuffer.offsets)
}