net

package
v0.0.0-...-b6f29c3 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2020 License: ISC Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Packet

type Packet struct {
	Opcode      byte
	FrameBuffer []byte
	ReadIndex   int

	Bare bool
	// contains filtered or unexported fields
}

Packet The definition of a game handlers. Generally, these are commands, indexed by their Opcode(0-255), with

a 5000-byte buffer for arguments, stored in FrameBuffer.  If the handlers is bare, raw data is intended to be
transmitted when writing the handlers structure to a socket, otherwise we put a 2-byte unsigned short for the
length of the arguments buffer(plus one because the opcode is included in the payload size), and the 1-byte
opcode at the start of the handlers, as a header for the client to easily parse the information for each frame.

func NewEmptyPacket

func NewEmptyPacket(opcode byte) *Packet

NewEmptyPacket Creates a new handlers instance intended for sending formatted data to the client.

func NewPacket

func NewPacket(opcode byte, payload []byte) *Packet

NewPacket Creates a new handlers instance.

func NewReplyPacket

func NewReplyPacket(src []byte) *Packet

NewReplyPacket Creates a new handlers instance intended for sending raw data to the client.

func (*Packet) AddBitmask

func (p *Packet) AddBitmask(value int, numBits int) *Packet

AddBitmask Packs value into the numBits next bits of the packetbuilders byte buffer. Note: This method only keeps track of the data that it has written to the buffer; it will overwrite any non-bitmasked values in the buffer starting at the beginning.

func (*Packet) AddBoolean

func (p *Packet) AddBoolean(b bool) *Packet

AddBoolean Adds a single byte to the payload, with the value 1 if b is true, and 0 if b is false.

func (*Packet) AddBytes

func (p *Packet) AddBytes(b []byte) *Packet

AddBytes Adds byte array to handlers payload

func (*Packet) AddEncryptedString

func (p *Packet) AddEncryptedString(s string) *Packet

func (*Packet) AddFramedString

func (p *Packet) AddFramedString(s string) *Packet

func (*Packet) AddInt8

func (p *Packet) AddInt8(b int8) *Packet

AddInt8 Adds an 8-bit signed integer to the handlers payload.

func (*Packet) AddSignedBits

func (p *Packet) AddSignedBits(value int, numBits int) *Packet

AddSignedBits adds the value with the first bit masked off

func (*Packet) AddSmart0816

func (p *Packet) AddSmart0816(i int) *Packet

func (*Packet) AddSmart0832

func (p *Packet) AddSmart0832(i int) *Packet

func (*Packet) AddSmart1632

func (p *Packet) AddSmart1632(i int) *Packet

func (*Packet) AddString

func (p *Packet) AddString(s string) *Packet

func (*Packet) AddUint16

func (p *Packet) AddUint16(s uint16) *Packet

AddUint16 Adds a 16-bit integer to the handlers payload.

func (*Packet) AddUint32

func (p *Packet) AddUint32(i uint32) *Packet

AddUint32 Adds a 32-bit integer to the handlers payload.

func (*Packet) AddUint64

func (p *Packet) AddUint64(l uint64) *Packet

AddUint64 Adds a 64-bit integer to the handlers payload.

func (*Packet) AddUint8

func (p *Packet) AddUint8(b uint8) *Packet

AddUint8 Adds an 8-bit integer to the handlers payload.

func (*Packet) AddUint8or32

func (p *Packet) AddUint8or32(i uint32) *Packet

AddUint8or32 Adds a 32-bit integer or an 8-byte integer to the handlers payload, depending on value. TODO: Deprecate and remove this in favor of above, improved name

func (*Packet) Available

func (p *Packet) Available() int

Available returns available read buffer bytes count.

func (*Packet) Capacity

func (p *Packet) Capacity() int

Capacity returns the byte capacity left for this buffer

func (*Packet) EnsureCapacity

func (p *Packet) EnsureCapacity(l int)

func (*Packet) Flip

func (p *Packet) Flip()

Flip Resets the read buffer caret to zero.

func (*Packet) Length

func (p *Packet) Length() int

Length returns length of byte buffer.

func (*Packet) Read

func (p *Packet) Read(buf []byte) int

func (*Packet) ReadBoolean

func (p *Packet) ReadBoolean() bool

ReadBoolean Returns true if the next payload byte isn't 0

func (*Packet) ReadInt8

func (p *Packet) ReadInt8() int8

ReadInt8 returns the signed interpretation of the next payload byte.

func (*Packet) ReadString

func (p *Packet) ReadString() string

ReadString Read the next variable-length C-string from the handlers payload and return it as a Go-string. This will keep reading data until it reaches a string termination byte. String termination bytes in order of precedence: NULL (hex:0x00, escape-seq:'\x00', decimal:0); NewLine/LineFeed (hex:0xA, escape-seq:'\n', decimal:10)

func (*Packet) ReadStringN

func (p *Packet) ReadStringN(n int) (val string)

ReadStringN Reads the next n bytes from the payload and returns it as a UTF-8 string, regardless of payload contents.

func (*Packet) ReadUByte

func (p *Packet) ReadUByte() byte

func (*Packet) ReadUint128

func (p *Packet) ReadUint128() (lsb uint64, msb uint64)

ReadUint128 Read the next 128-bit integer from the handlers payload, returns it as 2 uint64 words,

func (*Packet) ReadUint16

func (p *Packet) ReadUint16() int

ReadUint16 Read the next 16-bit integer from the handlers payload.

func (*Packet) ReadUint32

func (p *Packet) ReadUint32() int

ReadUint32 Read the next 32-bit integer from the handlers payload.

func (*Packet) ReadUint64

func (p *Packet) ReadUint64() uint64

ReadUint64 Read the next 64-bit integer from the handlers payload.

func (*Packet) ReadUint8

func (p *Packet) ReadUint8() uint8

ReadUint8 Read the next 8-bit integer from the handlers payload.

func (*Packet) Rewind

func (p *Packet) Rewind(n int) error

Rewind rewinds the reader index by n bytes

func (*Packet) Skip

func (p *Packet) Skip(n int) error

Skip skips the reader index by n bytes

func (*Packet) String

func (p *Packet) String() string

func (*Packet) WriteIndex

func (p *Packet) WriteIndex() int

type WriteFlusher

type WriteFlusher interface {
	io.Writer
	Flush() error
}

WriteFlusher

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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