packets

package
v0.0.0-...-a5005bf Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeArray = iota
	TypeByte
	TypeBool
	TypeInt16
	TypeInt32
	TypeInt64
	TypeVarInt
	TypeFloat32
	TypeFloat64
	TypeUUID
	TypeVarLong
	TypeByteArray
	TypeString
	TypeNBT
	TypePosition
	TypeSlot
	TypeBitSet
)
View Source
const (
	MaxPacketSize = 2097151
)

Variables

View Source
var ArrayLengthPrefixed = func(_ *PacketData) int {
	return arrayLengthPrefix
}

Functions

This section is empty.

Types

type ArrayLengthOption

type ArrayLengthOption = func(*PacketData) int

func ArrayLengthDerive

func ArrayLengthDerive(fieldName string) ArrayLengthOption

func ArrayLengthStatic

func ArrayLengthStatic(length int) ArrayLengthOption

type ArrayValue

type ArrayValue = []PacketData

type CFB8

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

func (*CFB8) XORKeyStream

func (c *CFB8) XORKeyStream(dst, src []byte)

type CipherStream

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

func NewCipherStream

func NewCipherStream(key []byte) (*CipherStream, error)

func (*CipherStream) WrapReader

func (cs *CipherStream) WrapReader(reader io.Reader) io.Reader

func (*CipherStream) WrapWriter

func (cs *CipherStream) WrapWriter(writer io.Writer) io.Writer

type ConvertedArrayValue

type ConvertedArrayValue = func(*PacketDefinition) ArrayValue

func ConvertArrayValue

func ConvertArrayValue[T any](data []T, convertFunc func(T, *PacketData)) ConvertedArrayValue

type Field

type Field struct {
	Type                   int
	Value                  any
	Blueprint              any
	ArrayElementDefinition *PacketDefinition
	ArrayLengthOption      ArrayLengthOption
	FieldOptions           []PacketFieldOpt
}

type PacketData

type PacketData struct {
	PacketID int
	Fields   []*Field
	// contains filtered or unexported fields
}

func (*PacketData) Any

func (pd *PacketData) Any(name string) any

func (*PacketData) Array

func (pd *PacketData) Array(name string) ArrayValue

func (*PacketData) BitSet

func (pd *PacketData) BitSet(name string) *types.BitSet

func (*PacketData) Bool

func (pd *PacketData) Bool(name string) bool

func (*PacketData) Byte

func (pd *PacketData) Byte(name string) byte

func (*PacketData) ByteArray

func (pd *PacketData) ByteArray(name string) []byte

func (*PacketData) Float32

func (pd *PacketData) Float32(name string) float32

func (*PacketData) Float64

func (pd *PacketData) Float64(name string) float64

func (*PacketData) Int16

func (pd *PacketData) Int16(name string) int16

func (*PacketData) Int32

func (pd *PacketData) Int32(name string) int32

func (*PacketData) Int64

func (pd *PacketData) Int64(name string) int64

func (*PacketData) NBT

func (pd *PacketData) NBT(name string) any

func (*PacketData) Position

func (pd *PacketData) Position(name string) *types.Position

func (*PacketData) Set

func (pd *PacketData) Set(name string, value any) *PacketData

func (*PacketData) SetArray

func (pd *PacketData) SetArray(name string, value ConvertedArrayValue) *PacketData

func (*PacketData) Slot

func (pd *PacketData) Slot(name string) *types.SlotData

func (*PacketData) String

func (pd *PacketData) String(name string) string

func (*PacketData) UUID

func (pd *PacketData) UUID(name string) types.UUID

func (*PacketData) VarInt

func (pd *PacketData) VarInt(name string) int

func (*PacketData) VarLong

func (pd *PacketData) VarLong(name string) int64

func (*PacketData) WriteTo

func (pd *PacketData) WriteTo(writer io.Writer) (int64, error)

type PacketDefinition

type PacketDefinition struct {
	PacketID int
	Fields   []*Field
	// contains filtered or unexported fields
}

func Packet

func Packet(opts ...PacketOpt) *PacketDefinition

func (*PacketDefinition) AddField

func (pd *PacketDefinition) AddField(name string, fieldType int)

func (*PacketDefinition) New

func (pd *PacketDefinition) New() *PacketData

func (*PacketDefinition) Read

func (pd *PacketDefinition) Read(reader io.Reader) (*PacketData, error)

func (*PacketDefinition) SetBlueprint

func (pd *PacketDefinition) SetBlueprint(name string, blueprint any)

type PacketDelivery

type PacketDelivery struct {
	PacketID int
	Header   *PacketHeader
	Reader   io.Reader
}

type PacketFieldOpt

type PacketFieldOpt = func(data *PacketData) bool

func OnlyIfEqual

func OnlyIfEqual(fieldName string, value any) PacketFieldOpt

func OnlyIfFalse

func OnlyIfFalse(fieldName string) PacketFieldOpt

func OnlyIfTrue

func OnlyIfTrue(fieldName string) PacketFieldOpt

type PacketHeader

type PacketHeader struct {
	PacketSize           int
	UncompressedDataSize int
	UseCompression       bool
}

type PacketOpt

type PacketOpt = func(*PacketDefinition)

func Array

func Array(name string, lengthOption ArrayLengthOption, fields ...PacketOpt) PacketOpt

func ArrayWithOptions

func ArrayWithOptions(name string, lengthOption ArrayLengthOption, fields []PacketOpt, opts ...PacketFieldOpt) PacketOpt

func BitSetField

func BitSetField(name string, opts ...PacketFieldOpt) PacketOpt

func Bool

func Bool(name string, opts ...PacketFieldOpt) PacketOpt

func Byte

func Byte(name string, opts ...PacketFieldOpt) PacketOpt

func ByteArray

func ByteArray(name string, opts ...PacketFieldOpt) PacketOpt

func Fields

func Fields(opts ...PacketOpt) []PacketOpt

func Float32

func Float32(name string, opts ...PacketFieldOpt) PacketOpt

func Float64

func Float64(name string, opts ...PacketFieldOpt) PacketOpt

func ID

func ID(id int) PacketOpt

func Int16

func Int16(name string, opts ...PacketFieldOpt) PacketOpt

func Int32

func Int32(name string, opts ...PacketFieldOpt) PacketOpt

func Int64

func Int64(name string, opts ...PacketFieldOpt) PacketOpt

func NBT

func NBT(name string, blueprint any, opts ...PacketFieldOpt) PacketOpt

func PositionField

func PositionField(name string, opts ...PacketFieldOpt) PacketOpt

func Slot

func Slot(name string, opts ...PacketFieldOpt) PacketOpt

func String

func String(name string, opts ...PacketFieldOpt) PacketOpt

func UUIDField

func UUIDField(name string, opts ...PacketFieldOpt) PacketOpt

func VarInt

func VarInt(name string, opts ...PacketFieldOpt) PacketOpt

func VarLong

func VarLong(name string, opts ...PacketFieldOpt) PacketOpt

type PacketReader

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

func NewPacketReader

func NewPacketReader(reader io.Reader) *PacketReader

func (*PacketReader) Read

func (pr *PacketReader) Read() (*PacketDelivery, error)

func (*PacketReader) SetBuffered

func (pr *PacketReader) SetBuffered(buffered bool)

func (*PacketReader) SetCompression

func (pr *PacketReader) SetCompression(threshold int)

func (*PacketReader) SetEncryption

func (pr *PacketReader) SetEncryption(cipherStream *CipherStream)

type PacketWriter

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

func NewPacketWriter

func NewPacketWriter(writer io.Writer) *PacketWriter

func (*PacketWriter) SetCompression

func (pw *PacketWriter) SetCompression(threshold int)

func (*PacketWriter) SetEncryption

func (pw *PacketWriter) SetEncryption(cipherStream *CipherStream)

func (*PacketWriter) Write

func (pw *PacketWriter) Write(packet *PacketData) error

Jump to

Keyboard shortcuts

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