Documentation ¶
Index ¶
- Constants
- Variables
- func NewDecryptReader(r io.Reader, secret []byte) (reader io.Reader, err error)
- func NewEncryptWriter(w io.Writer, secret []byte) (wr io.Writer, err error)
- type Decoder
- type Encoder
- func (e *Encoder) SetCompression(threshold, level int) (err error)
- func (e *Encoder) SetProtocol(protocol proto.Protocol)
- func (e *Encoder) SetState(state *state.Registry)
- func (e *Encoder) SetWriter(w io.Writer)
- func (e *Encoder) Sync(fn func() error) error
- func (e *Encoder) Write(payload []byte) (n int, err error)
- func (e *Encoder) WriteBuf(payload *bytes.Buffer) (n int, err error)
- func (e *Encoder) WritePacket(packet proto.Packet) (n int, err error)
Constants ¶
const ( VanillaMaximumUncompressedSize = 2 * 1024 * 1024 // 2MiB HardMaximumUncompressedSize = 16 * 1024 * 1024 // 16MiB UncompressedCap = VanillaMaximumUncompressedSize )
Variables ¶
var ErrDecoderLeftBytes = errors.New("decoder dis not read all packet data")
Indicates a packet was known and successfully decoded by it's registered decoder, but the decoder has not read all of the packet's data.
This may happen in cases where
- the decoder has a bug
- the decoder does not handle the case for the new protocol version of the packet changed by Mojang/Minecraft
- someone (server/client) has sent valid bytes in the beginning of the packet's data that the packet's decoder could successfully decode, but then the data contains even more bytes (the left bytes)
Functions ¶
func NewDecryptReader ¶
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is a synchronized packet decoder.
func NewDecoder ¶
func (*Decoder) ReadPacket ¶
func (d *Decoder) ReadPacket() (ctx *proto.PacketContext, err error)
ReadPacket blocks Decoder's mutex when the next packet's frame is known and stays blocked until the full packet from the underlying io.Reader is read.
This is to ensure the mutex is not locked while being blocked by the first Read call (e.g. underlying io.Reader is a net.Conn).
func (*Decoder) SetCompressionThreshold ¶
func (*Decoder) SetProtocol ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is a synchronized packet encoder.
func (*Encoder) SetCompression ¶
func (*Encoder) SetProtocol ¶
func (*Encoder) Sync ¶ added in v0.0.2
Sync locks the encoder while running fn, making sure no writes calls are run during this call.
func (*Encoder) Write ¶
Write encodes and writes the uncompressed and unencrypted payload (packed id + data).