util

package
v0.0.0-...-d63482c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxStringSize = bufio.MaxScanTokenSize
)
View Source
const ForgeMaxArrayLength = math.MaxInt32 & 0x1FFF9A

Variables

This section is empty.

Functions

func DefaultJsonCodec

func DefaultJsonCodec() codec.Codec

DefaultJsonCodec returns a legacy supportive codec.

func JsonCodec

func JsonCodec(protocol proto.Protocol) codec.Codec

JsonCodec returns the appropriate codec for the given protocol version. This is used to constrain messages sent to older clients.

func LatestJsonCodec

func LatestJsonCodec() codec.Codec

func Marshal

func Marshal(protocol proto.Protocol, c component.Component) ([]byte, error)

Marshal marshals a component into JSON.

func MarshalPlain

func MarshalPlain(c component.Component) (string, error)

MarshalPlain marshals a component into plain text. A component.Translation is formatted as "{key}".

func PReadBool

func PReadBool(r io.Reader, b *bool)

func PReadByte

func PReadByte(rd io.Reader, b *byte)

func PReadByteVal

func PReadByteVal(rd io.Reader) byte

func PReadBytes

func PReadBytes(rd io.Reader, b *[]byte)

func PReadBytesVal

func PReadBytesVal(rd io.Reader) []byte

func PReadInt

func PReadInt(r io.Reader, i *int)

func PReadInt64

func PReadInt64(r io.Reader, i *int64)

func PReadInt64Val

func PReadInt64Val(rd io.Reader) int64

func PReadIntVal

func PReadIntVal(rd io.Reader) int

func PReadString

func PReadString(rd io.Reader, s *string)

func PReadStringMax

func PReadStringMax(rd io.Reader, s *string, max int)

func PReadStringVal

func PReadStringVal(rd io.Reader) string

func PReadStrings

func PReadStrings(r io.Reader, i *[]string)

func PReadUint8

func PReadUint8(rd io.Reader, i *uint8)

func PVarInt

func PVarInt(rd io.Reader, i *int)

func PWriteBool

func PWriteBool(w io.Writer, b bool)

func PWriteByte

func PWriteByte(w io.Writer, b byte)

func PWriteBytes

func PWriteBytes(wr io.Writer, b []byte)

func PWriteCompoundBinaryTag

func PWriteCompoundBinaryTag(w io.Writer, protocol proto.Protocol, cbt CompoundBinaryTag)

func PWriteInt

func PWriteInt(w io.Writer, i int)

func PWriteInt64

func PWriteInt64(w io.Writer, i int64)

func PWriteString

func PWriteString(wr io.Writer, s string)

func PWriteStrings

func PWriteStrings(w io.Writer, s []string)

func PWriteVarInt

func PWriteVarInt(wr io.Writer, i int)

func ReadBool

func ReadBool(reader io.Reader) (val bool, err error)

func ReadByte

func ReadByte(reader io.Reader) (val byte, err error)

func ReadBytes

func ReadBytes(rd io.Reader) ([]byte, error)

func ReadBytes17

func ReadBytes17(rd io.Reader) ([]byte, error)

ReadBytes17 reads bytes with the Minecraft 1.7 style length.

func ReadBytesLen

func ReadBytesLen(rd io.Reader, maxLength int) (bytes []byte, err error)

func ReadExtendedForgeShort

func ReadExtendedForgeShort(rd io.Reader) (int, error)

ReadExtendedForgeShort reads a Minecraft-style extended short from the specified {@code buf}.

func ReadFloat32

func ReadFloat32(reader io.Reader) (val float32, err error)

func ReadFloat64

func ReadFloat64(reader io.Reader) (val float64, err error)

func ReadInt

func ReadInt(rd io.Reader) (int, error)

func ReadInt16

func ReadInt16(reader io.Reader) (val int16, err error)

func ReadInt32

func ReadInt32(reader io.Reader) (val int32, err error)

func ReadInt64

func ReadInt64(reader io.Reader) (val int64, err error)

func ReadInt8

func ReadInt8(reader io.Reader) (val int8, err error)

func ReadIntArray

func ReadIntArray(rd io.Reader) ([]int, error)

func ReadKey

func ReadKey(rd io.Reader) (key.Key, error)

ReadKey reads a standard Mojang Text namespaced:key from the reader.

func ReadKeyArray

func ReadKeyArray(rd io.Reader) ([]key.Key, error)

ReadKeyArray reads a standard Mojang Text namespaced:key array from the reader.

func ReadProperties

func ReadProperties(rd io.Reader) (props []profile.Property, err error)

func ReadRawBytes

func ReadRawBytes(rd io.Reader) ([]byte, error)

Reads a non length prefixed string from the reader. This is necessary for parsing certain packets like the velocity login/hello packet (no length prefix).

func ReadString

func ReadString(rd io.Reader) (string, error)

func ReadStringArray

func ReadStringArray(rd io.Reader) ([]string, error)

func ReadStringMax

func ReadStringMax(rd io.Reader, max int) (string, error)

func ReadStringWithoutLen

func ReadStringWithoutLen(rd io.Reader) (string, error)

ReadStringWithoutLen reads a non length-prefixed string from the Reader. We need this for the legacy 1.7 version, being inconsistent when sending the plugin message channel brand.

func ReadUTF

func ReadUTF(rd io.Reader) (string, error)

ReadUTF util function as exists in Java

func ReadUUID

func ReadUUID(rd io.Reader) (id uuid.UUID, err error)

func ReadUUIDIntArray

func ReadUUIDIntArray(rd io.Reader) (uuid.UUID, error)

func ReadUint16

func ReadUint16(reader io.Reader) (val uint16, err error)

func ReadUint32

func ReadUint32(reader io.Reader) (val uint32, err error)

func ReadUint64

func ReadUint64(reader io.Reader) (val uint64, err error)

func ReadUint8

func ReadUint8(reader io.Reader) (val uint8, err error)

func ReadUnixMilli

func ReadUnixMilli(rd io.Reader) (time.Time, error)

func ReadVarInt

func ReadVarInt(r io.Reader) (result int, err error)

func ReadVarIntArray

func ReadVarIntArray(rd io.Reader) ([]int, error)

ReadVarIntArray reads a VarInt array from the reader.

func Recover

func Recover(err *error)

Recover is a helper function to recover from a panic and set the error pointer to the recovered error. If the panic is not an error, it will be re-panicked.

Usage:

func fn() (err error) {
	defer Recover(&err)
	// code that may panic(err)
}

func RecoverFunc

func RecoverFunc(fn func() error) (err error)

RecoverFunc is a helper function to recover from a panic and set the error pointer to the recovered error. If the panic is not an error, it will be re-panicked.

Usage:

return RecoverFunc(func() error {
	// code that may panic(err)
})

func WriteBinaryTag

func WriteBinaryTag(w io.Writer, protocol proto.Protocol, bt BinaryTag) error

WriteBinaryTag writes a binary tag to the provided writer.

func WriteBool

func WriteBool(writer io.Writer, val bool) (err error)

func WriteByte

func WriteByte(writer io.Writer, val byte) (err error)

equal to WriteUint8

func WriteBytes

func WriteBytes(wr io.Writer, b []byte) (err error)

func WriteBytes17

func WriteBytes17(wr io.Writer, b []byte, allowExtended bool) error

func WriteComponent

func WriteComponent(wr io.Writer, protocol proto.Protocol, c component.Component) error

func WriteExtendedForgeShort

func WriteExtendedForgeShort(wr io.Writer, toWrite int) (err error)

func WriteFloat32

func WriteFloat32(writer io.Writer, val float32) (err error)

func WriteFloat64

func WriteFloat64(writer io.Writer, val float64) (err error)

func WriteInt

func WriteInt(writer io.Writer, val int) (err error)

func WriteInt16

func WriteInt16(writer io.Writer, val int16) (err error)

func WriteInt32

func WriteInt32(writer io.Writer, val int32) (err error)

func WriteInt64

func WriteInt64(writer io.Writer, val int64) (err error)

func WriteInt8

func WriteInt8(writer io.Writer, val int8) (err error)

equal to WriteUint8

func WriteKey

func WriteKey(wr io.Writer, k key.Key) error

WriteKey writes a standard Mojang Text namespaced:key to the writer.

func WriteKeyArray

func WriteKeyArray(wr io.Writer, keys []key.Key) error

WriteKeyArray writes a standard Mojang Text namespaced:key array to the writer.

func WriteProperties

func WriteProperties(wr io.Writer, properties []profile.Property) error

func WriteRawBytes

func WriteRawBytes(wr io.Writer, b []byte) (err error)

Writes a raw strema of bytes to a file with no length prefix. Necessary for the Velocity hello/login packet (it uses a non-standard packet format)

func WriteString

func WriteString(writer io.Writer, val string) (err error)

func WriteStrings

func WriteStrings(wr io.Writer, a []string) error

func WriteUTF

func WriteUTF(wr io.Writer, s string) error

WriteUTF util function as exists in Java

func WriteUUID

func WriteUUID(wr io.Writer, uuid uuid.UUID) error

Encoded as an unsigned 128-bit integer (or two unsigned 64-bit integers: the most significant 64 bits and then the least significant 64 bits)

func WriteUUIDIntArray

func WriteUUIDIntArray(wr io.Writer, id uuid.UUID) error

func WriteUint16

func WriteUint16(writer io.Writer, val uint16) (err error)

func WriteUint32

func WriteUint32(writer io.Writer, val uint32) (err error)

func WriteUint64

func WriteUint64(writer io.Writer, val uint64) (err error)

func WriteUint8

func WriteUint8(writer io.Writer, val uint8) (err error)

equal to WriteByte

func WriteUint8N

func WriteUint8N(writer io.Writer, val uint8) (n int, err error)

func WriteVarInt

func WriteVarInt(writer io.Writer, val int) (err error)

func WriteVarIntArray

func WriteVarIntArray(wr io.Writer, array []int) error

WriteVarIntArray writes a variable-length integer array to the writer.

func WriteVarIntN

func WriteVarIntN(writer io.Writer, val int) (n int, err error)

Types

type BinaryTag

type BinaryTag = nbt.RawMessage

BinaryTag is a binary tag.

func ReadBinaryTag

func ReadBinaryTag(r io.Reader, protocol proto.Protocol) (bt BinaryTag, err error)

ReadBinaryTag reads a binary tag from the provided reader.

type CompoundBinaryTag

type CompoundBinaryTag = BinaryTag

CompoundBinaryTag is a compound binary tag.

func ReadCompoundTag

func ReadCompoundTag(r io.Reader, protocol proto.Protocol) (CompoundBinaryTag, error)

ReadCompoundTag reads a compound binary tag from the provided reader.

type PReader

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

func PanicReader

func PanicReader(r io.Reader) *PReader

func (*PReader) Bool

func (r *PReader) Bool(b *bool)

func (*PReader) Byte

func (r *PReader) Byte(b *byte)

func (*PReader) Bytes

func (r *PReader) Bytes(b *[]byte)

func (*PReader) Int

func (r *PReader) Int(i *int)

func (*PReader) Int64

func (r *PReader) Int64(i *int64)

func (*PReader) Ok

func (r *PReader) Ok() bool

func (*PReader) String

func (r *PReader) String(s *string)

func (*PReader) StringMax

func (r *PReader) StringMax(s *string, max int)

func (*PReader) Strings

func (r *PReader) Strings(i *[]string)

func (*PReader) Uint8

func (r *PReader) Uint8(i *uint8)

func (*PReader) VarInt

func (r *PReader) VarInt(i *int)

type PWriter

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

func PanicWriter

func PanicWriter(w io.Writer) *PWriter

func (*PWriter) Bool

func (w *PWriter) Bool(b bool)

func (*PWriter) Byte

func (w *PWriter) Byte(b byte)

func (*PWriter) Bytes

func (w *PWriter) Bytes(b []byte)

func (*PWriter) CompoundBinaryTag

func (w *PWriter) CompoundBinaryTag(cbt CompoundBinaryTag, protocol proto.Protocol)

func (*PWriter) Int

func (w *PWriter) Int(i int)

func (*PWriter) Int64

func (w *PWriter) Int64(i int64)

func (*PWriter) String

func (w *PWriter) String(s string)

func (*PWriter) Strings

func (w *PWriter) Strings(s []string)

func (*PWriter) VarInt

func (w *PWriter) VarInt(i int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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