planet

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2020 License: MIT Imports: 8 Imported by: 0

README

planet

PlayerNetwork UDP Protocol

Documentation

Index

Constants

View Source
const (
	AckSize                   = 32
	RttSmoothingFactor        = 0.0025
	PacketLossSmoothingFactor = 0.50
	BandwidthSmoothingFactor  = 0.10
)
View Source
const (

	// SizeUint8 is the byte size of a uint8.
	SizeUint8 = 1
	// SizeUint16 is the byte size of a uint16.
	SizeUint16 = 2
	// SizeUint32 is the byte size of a uint32.
	SizeUint32 = 4
	// SizeUint64 is the byte size of a uint64.
	SizeUint64 = 8

	// SizeInt8 is the byte size of a int8.
	SizeInt8 = 1
	// SizeInt16 is the byte size of a int16.
	SizeInt16 = 2
	// SizeInt32 is the byte size of a int32.
	SizeInt32 = 4
	// SizeInt64 is the byte size of a int64.
	SizeInt64 = 8

	// SizeFloat32 is the byte size of a float32.
	SizeFloat32 = 4
	// SizeFloat64 is the byte size of a float64.
	SizeFloat64 = 8

	// SizeByte is the byte size of a byte.
	// The `byte` type is aliased (by Go definition) to uint8.
	SizeByte = 1

	// SizeBool is the byte size of a bool.
	// The `bool` type is aliased (by flatbuffers convention) to uint8.
	SizeBool = 1

	// SizeSOffsetT is the byte size of an SOffsetT.
	// The `SOffsetT` type is aliased (by flatbuffers convention) to int32.
	SizeSOffsetT = 4
	// SizeUOffsetT is the byte size of an UOffsetT.
	// The `UOffsetT` type is aliased (by flatbuffers convention) to uint32.
	SizeUOffsetT = 4
	// SizeVOffsetT is the byte size of an VOffsetT.
	// The `VOffsetT` type is aliased (by flatbuffers convention) to uint16.
	SizeVOffsetT = 2
)
View Source
const DATA_SIZE_BYTES = 15
View Source
const PACKET_UDP_HEADER_BYTES = 17

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	Buf []byte // the backing byte slice
	Pos int    // current position in read/write
}

Buffer is a helper struct for serializing and deserializing as the caller does not need to externally manage where in the buffer they are currently reading or writing to.

func NewBuffer

func NewBuffer(size int) *Buffer

Creates a new Buffer with a backing byte slice of the provided size

func NewBufferFromBytes

func NewBufferFromBytes(buf []byte) *Buffer

Creates a new buffer from a byte slice

func NewBufferFromRef

func NewBufferFromRef(buf []byte) *Buffer

Creates a new Buffer using the original backing slice

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Returns the backing byte slice

func (*Buffer) Copy

func (b *Buffer) Copy() *Buffer

Returns a copy of Buffer

func (*Buffer) GetByte

func (b *Buffer) GetByte() (byte, error)

GetByte decodes a little-endian byte

func (*Buffer) GetBytes

func (b *Buffer) GetBytes(length int) ([]byte, error)

GetBytes returns a byte slice possibly smaller than length if bytes are not available from the reader.

func (*Buffer) GetInt16

func (b *Buffer) GetInt16() (int16, error)

GetInt16 decodes a little-endian int16 from the buffer

func (*Buffer) GetInt32

func (b *Buffer) GetInt32() (int32, error)

GetInt32 decodes a little-endian int32 from the buffer

func (*Buffer) GetInt64

func (b *Buffer) GetInt64() (int64, error)

GetInt64 decodes a little-endian int64 from the buffer

func (*Buffer) GetInt8

func (b *Buffer) GetInt8() (int8, error)

GetInt8 decodes a little-endian int8 from the buffer

func (*Buffer) GetUint16

func (b *Buffer) GetUint16() (uint16, error)

GetUint16 decodes a little-endian uint16 from the buffer

func (*Buffer) GetUint32

func (b *Buffer) GetUint32() (uint32, error)

GetUint32 decodes a little-endian uint32 from the buffer

func (*Buffer) GetUint64

func (b *Buffer) GetUint64() (uint64, error)

GetUint64 decodes a little-endian uint64 from the buffer

func (*Buffer) GetUint8

func (b *Buffer) GetUint8() (uint8, error)

GetUint8 decodes a little-endian uint8 from the buffer

func (*Buffer) Len

func (b *Buffer) Len() int

Gets the length of the backing byte slice

func (*Buffer) Reset

func (b *Buffer) Reset()

Resets the position back to beginning of buffer

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(n byte)

WriteByte encodes a little-endian uint8 into the buffer.

func (*Buffer) WriteBytes

func (b *Buffer) WriteBytes(src []byte)

WriteBytes encodes a little-endian byte slice into the buffer

func (*Buffer) WriteBytesN

func (b *Buffer) WriteBytesN(src []byte, length int)

WriteBytes encodes a little-endian byte slice into the buffer

func (*Buffer) WriteFloat32

func (b *Buffer) WriteFloat32(n float32)

WriteFloat32 encodes a little-endian float32 into the buffer.

func (*Buffer) WriteFloat64

func (b *Buffer) WriteFloat64(buf []byte, n float64)

WriteFloat64 encodes a little-endian float64 into the buffer.

func (*Buffer) WriteInt16

func (b *Buffer) WriteInt16(n int16)

WriteInt16 encodes a little-endian int16 into the buffer.

func (*Buffer) WriteInt32

func (b *Buffer) WriteInt32(n int32)

WriteInt32 encodes a little-endian int32 into the buffer.

func (*Buffer) WriteInt64

func (b *Buffer) WriteInt64(n int64)

WriteInt64 encodes a little-endian int64 into the buffer.

func (*Buffer) WriteInt8

func (b *Buffer) WriteInt8(n int8)

WriteInt8 encodes a little-endian int8 into the buffer.

func (*Buffer) WriteUint16

func (b *Buffer) WriteUint16(n uint16)

WriteUint16 encodes a little-endian uint16 into the buffer.

func (*Buffer) WriteUint32

func (b *Buffer) WriteUint32(n uint32)

WriteUint32 encodes a little-endian uint32 into the buffer.

func (*Buffer) WriteUint64

func (b *Buffer) WriteUint64(n uint64)

WriteUint64 encodes a little-endian uint64 into the buffer.

func (*Buffer) WriteUint8

func (b *Buffer) WriteUint8(n uint8)

WriteUint8 encodes a little-endian uint8 into the buffer.

type PacketAck

type PacketAck struct {
	Bytes    uint
	SentTime time.Time
	RecvTime time.Time
	Acked    bool
	Reaible  bool
}

type PacketUDP

type PacketUDP struct {
	Session     uint32
	Protocol    uint16
	Sequence    uint16
	Ack         uint16
	AckBitfield uint32
	DataType    uint8
	DataSize    uint16
	Data        []byte
}

func NewPacket

func NewPacket(buf []byte) *PacketUDP

func (*PacketUDP) Write

func (p *PacketUDP) Write() []byte

type PlayerNetwork

type PlayerNetwork struct {
	// contains filtered or unexported fields
}

func NewPlayerNetwork

func NewPlayerNetwork(conn *net.UDPConn, session uint32) *PlayerNetwork

func (*PlayerNetwork) AckBandwidth

func (p *PlayerNetwork) AckBandwidth() float32

func (*PlayerNetwork) PacketLoss

func (p *PlayerNetwork) PacketLoss() float32

func (*PlayerNetwork) RTT

func (p *PlayerNetwork) RTT() float32

func (*PlayerNetwork) ReceivePacket

func (p *PlayerNetwork) ReceivePacket(pkt *PacketUDP, recvTime time.Time, addr *net.UDPAddr, process func(pkt *PacketUDP, addr *net.UDPAddr))

func (*PlayerNetwork) RecvBandwidth

func (p *PlayerNetwork) RecvBandwidth() float32

func (*PlayerNetwork) RemoteSequence

func (p *PlayerNetwork) RemoteSequence() uint16

func (*PlayerNetwork) SendPacket

func (p *PlayerNetwork) SendPacket(protocol uint16, datatype uint8, data []byte, reaible bool) error

func (*PlayerNetwork) SendPacketToUDP

func (p *PlayerNetwork) SendPacketToUDP(protocol uint16, datatype uint8, data []byte, addr *net.UDPAddr, reaible bool) error

func (*PlayerNetwork) SentBandwidth

func (p *PlayerNetwork) SentBandwidth() float32

func (*PlayerNetwork) Update added in v1.1.0

func (p *PlayerNetwork) Update(now time.Time)

type ReaibleAck added in v1.1.0

type ReaibleAck struct {
	Packet *PacketUDP
	Addr   *net.UDPAddr
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL