util

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 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 added in v0.35.0

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

Marshal marshals a component into JSON.

func MarshalPlain added in v0.19.0

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

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

func PReadBool added in v0.35.0

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

func PReadByte added in v0.35.0

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

func PReadByteVal added in v0.35.0

func PReadByteVal(rd io.Reader) byte

func PReadBytes added in v0.35.0

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

func PReadBytesVal added in v0.35.0

func PReadBytesVal(rd io.Reader) []byte

func PReadInt added in v0.35.0

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

func PReadInt64 added in v0.35.0

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

func PReadInt64Val added in v0.35.0

func PReadInt64Val(rd io.Reader) int64

func PReadIntVal added in v0.37.0

func PReadIntVal(rd io.Reader) int

func PReadString added in v0.35.0

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

func PReadStringMax added in v0.36.0

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

func PReadStringVal added in v0.35.0

func PReadStringVal(rd io.Reader) string

func PReadStrings added in v0.35.0

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

func PReadUint8 added in v0.36.0

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

func PVarInt added in v0.35.0

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

func PWriteBool added in v0.35.0

func PWriteBool(w io.Writer, b bool)

func PWriteByte added in v0.35.0

func PWriteByte(w io.Writer, b byte)

func PWriteBytes added in v0.35.0

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

func PWriteCompoundBinaryTag added in v0.35.0

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

func PWriteInt added in v0.35.0

func PWriteInt(w io.Writer, i int)

func PWriteInt64 added in v0.35.0

func PWriteInt64(w io.Writer, i int64)

func PWriteString added in v0.35.0

func PWriteString(wr io.Writer, s string)

func PWriteStrings added in v0.35.0

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

func PWriteVarInt added in v0.35.0

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 added in v0.12.0

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

func ReadKey added in v0.35.0

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

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

func ReadKeyArray added in v0.35.0

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 added in v0.15.1

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 added in v0.35.0

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 added in v0.19.0

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

func ReadVarInt

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

func ReadVarIntArray added in v0.35.0

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

ReadVarIntArray reads a VarInt array from the reader.

func Recover added in v0.35.0

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 added in v0.35.0

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 added in v0.35.0

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 added in v0.19.0

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 added in v0.12.0

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 added in v0.35.0

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

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

func WriteKeyArray added in v0.35.0

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 added in v0.15.1

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 added in v0.35.0

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 added in v0.19.1

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

func WriteVarInt

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

func WriteVarIntArray added in v0.35.0

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

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

func WriteVarIntN added in v0.19.1

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

Types

type BinaryTag added in v0.35.0

type BinaryTag = nbt.RawMessage

BinaryTag is a binary tag.

func ReadBinaryTag added in v0.35.0

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

ReadBinaryTag reads a binary tag from the provided reader.

type CompoundBinaryTag added in v0.35.0

type CompoundBinaryTag = BinaryTag

CompoundBinaryTag is a compound binary tag.

func ReadCompoundTag added in v0.35.0

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

ReadCompoundTag reads a compound binary tag from the provided reader.

type PReader added in v0.35.0

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

func PanicReader added in v0.35.0

func PanicReader(r io.Reader) *PReader

func (*PReader) Bool added in v0.35.0

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

func (*PReader) Byte added in v0.35.0

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

func (*PReader) Bytes added in v0.35.0

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

func (*PReader) Int added in v0.35.0

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

func (*PReader) Int64 added in v0.35.0

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

func (*PReader) Ok added in v0.35.0

func (r *PReader) Ok() bool

func (*PReader) String added in v0.35.0

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

func (*PReader) StringMax added in v0.36.0

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

func (*PReader) Strings added in v0.35.0

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

func (*PReader) Uint8 added in v0.36.0

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

func (*PReader) VarInt added in v0.35.0

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

type PWriter added in v0.35.0

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

func PanicWriter added in v0.35.0

func PanicWriter(w io.Writer) *PWriter

func (*PWriter) Bool added in v0.35.0

func (w *PWriter) Bool(b bool)

func (*PWriter) Byte added in v0.35.0

func (w *PWriter) Byte(b byte)

func (*PWriter) Bytes added in v0.35.0

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

func (*PWriter) CompoundBinaryTag added in v0.35.0

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

func (*PWriter) Int added in v0.35.0

func (w *PWriter) Int(i int)

func (*PWriter) Int64 added in v0.35.0

func (w *PWriter) Int64(i int64)

func (*PWriter) String added in v0.35.0

func (w *PWriter) String(s string)

func (*PWriter) Strings added in v0.35.0

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

func (*PWriter) VarInt added in v0.35.0

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