func (p *Packet) Flip() {
	p.ReadIndex = 0
}
Flip Resets the read buffer caret to zero.
package net
import (
	"math"
	"encoding/binary"
	"fmt"
	"io"
	"runtime/debug"
	"strconv"
	"strings"
	"github.com/spkaeros/rscgo/pkg/errors"
	"github.com/spkaeros/rscgo/pkg/log"
	"github.com/spkaeros/rscgo/pkg/strutil"
)
type WriteFlusher interface {
	io.Writer
	Flush() error
}
type Packet struct {
	Opcode      byte
	FrameBuffer []byte
	ReadIndex   int
	bitIndex    int
	Bare        bool
}
func NewPacket(opcode byte, payload []byte) *Packet {
	return &Packet{Opcode: opcode, FrameBuffer: payload, Bare: false}
}
func NewEmptyPacket(opcode byte) *Packet {
	return &Packet{Opcode: opcode, FrameBuffer: []byte{opcode}, Bare: false}
}
func NewReplyPacket(src []byte) *Packet {
	return &Packet{FrameBuffer: src, Bare: true}
}
func (p *Packet) ReadUint128() (lsb uint64, msb uint64) {
	return p.ReadUint64(), p.ReadUint64()
}
func (p *Packet) ReadUint64() uint64 {
	if checkError(p.Skip(8)) {
		return 0
	}
	return binary.BigEndian.Uint64(p.FrameBuffer[p.ReadIndex-8:])
}
func (p *Packet) ReadUint32() int {
	if checkError(p.Skip(4)) {
		return 0
	}
	return int(binary.BigEndian.Uint32(p.FrameBuffer[p.ReadIndex-4:]))
}
func (p *Packet) ReadUint16() int {
	if checkError(p.Skip(2)) {
		return 0
	}
	return int(binary.BigEndian.Uint16(p.FrameBuffer[p.ReadIndex-2:]))
}
func checkError(err error) bool {
	if err != nil {
		debug.PrintStack()
		log.Warn("Packet error:", err)
		return true
	}
	return false
}
func (p *Packet) ReadUint8() uint8 {
	if checkError(p.Skip(1)) {
		return 0
	}
	return p.FrameBuffer[p.ReadIndex-1] & 0xFF
}
func (p *Packet) ReadUByte() byte {
	return p.ReadUint8()
}
func (p *Packet) ReadInt8() int8 {
	if checkError(p.Skip(1)) {
		return 0
	}
	return int8(p.FrameBuffer[p.ReadIndex-1])
}
func (p *Packet) ReadBoolean() bool {
	if checkError(p.Skip(1)) {
		return false
	}
	return p.FrameBuffer[p.ReadIndex-1] != 0
}
func (p *Packet) Read(buf []byte) int {
	n := len(buf)
	if p.Available() < n {
		log.Warning.Println("PacketBufferError[OutOfBounds:Read] Tried to read too many bytes (" + strconv.Itoa(n) + ") from read buffer (length " + strconv.Itoa(p.Available()) + ")")
		return -1
	}
	copy(buf, p.FrameBuffer[p.ReadIndex:])
	if checkError(p.Skip(n)) {
		return -1
	}
	return n
}