Documentation ¶
Overview ¶
Package protocol implements functions for reading, writing, decoding, and encoding data for the Minecraft protocol.
Index ¶
- Variables
- type Packet
- func (p *Packet) Write(data []byte) (int, error)
- func (p *Packet) WriteBoolean(data bool)
- func (p *Packet) WriteByte(data byte) error
- func (p *Packet) WriteFloat32(data float32)
- func (p *Packet) WriteFloat64(data float64)
- func (p *Packet) WriteInt16(data int16)
- func (p *Packet) WriteInt32(data int32)
- func (p *Packet) WriteInt64(data int64)
- func (p *Packet) WriteSignedByte(data int8)
- func (p *Packet) WriteString(data string)
- func (p *Packet) WriteUInt16(data uint16)
- func (p *Packet) WriteVarInt(data int)
- func (p *Packet) WriteVarInt64(data int64)
- type PacketStream
- type Stream
- func (s Stream) DecodeReadFull(data []byte) error
- func (s Stream) GetPacketStream() (PacketStream, int, error)
- func (s Stream) ReadBoolean() (bool, error)
- func (s Stream) ReadByte() (byte, error)
- func (s Stream) ReadFloat32() (float32, error)
- func (s Stream) ReadFloat64() (float64, error)
- func (s Stream) ReadFull(data []byte) error
- func (s Stream) ReadInt16() (int16, error)
- func (s Stream) ReadInt32() (int32, error)
- func (s Stream) ReadInt64() (int64, error)
- func (s Stream) ReadSignedByte() (int8, error)
- func (s Stream) ReadString() (string, error)
- func (s Stream) ReadUInt16() (uint16, error)
- func (s Stream) ReadVarInt() (int, error)
- func (s Stream) ReadVarInt64() (int64, error)
- func (s Stream) WritePacket(p *Packet) error
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidData = errors.New("protocol: invalid data")
ErrInvalidData is returned when you attempt to read a piece of data that cannot possibly be of the type you are trying to read as.
Functions ¶
This section is empty.
Types ¶
type Packet ¶
type Packet struct {
Data []byte
}
A Packet represents a packet in the Minecraft protocol that is to be sent to the client. It is not used for receiving or reading packets.
func NewPacketWithID ¶
NewPacketWithID returns a new Packet with the Id written to the start of the Packet.
func (*Packet) WriteBoolean ¶
WriteBoolean writes a boolean to the Packet.
func (*Packet) WriteFloat32 ¶
WriteFloat32 writes a float32 (a single-precision float) to the Packet.
func (*Packet) WriteFloat64 ¶
WriteFloat64 writes a float64 (a double-precision float) to the Packet.
func (*Packet) WriteInt16 ¶
WriteInt16 writes an int16 (a short) to the Packet.
func (*Packet) WriteInt32 ¶
WriteInt32 writes an int32 to the Packet.
func (*Packet) WriteInt64 ¶
WriteInt64 writes an int64 (a long) to the Packet.
func (*Packet) WriteSignedByte ¶
WriteSignedByte writes an int8 to the Packet.
func (*Packet) WriteString ¶
WriteString writes a VarInt which is the length of the string, and the string itself to the Packet.
func (*Packet) WriteUInt16 ¶
WriteUInt16 writes an uint16 (an unsigned short) to the Packet.
func (*Packet) WriteVarInt ¶
WriteVarInt writes an int as a VarInt to the Packet.
func (*Packet) WriteVarInt64 ¶
WriteVarInt64 writes an int64 as a VarInt to the Packet.
This code is taken from thinkofdeath's steven (github.com/thinkofdeath/steven).
type PacketStream ¶
type PacketStream struct { Stream // contains filtered or unexported fields }
A PacketStream is a subset of a Stream which is limited to being only able to read a single packet from the stream.
func (PacketStream) ExhaustPacket ¶
func (s PacketStream) ExhaustPacket() (int, error)
ExhaustPacket reads all the remaining data from the PacketStream, so the cursor of the Stream is at the start of the next packet.
func (PacketStream) GetRemainingBytes ¶
func (s PacketStream) GetRemainingBytes() int
GetRemainingBytes returns the number of remaining bytes in the PacketStream for the current packet.
type Stream ¶
type Stream struct {
io.ReadWriter
}
A Stream represents a two-way stream of bytes to and from the client.
func NewStream ¶
func NewStream(readWriter io.ReadWriter) Stream
NewStream creates a new Stream from a io.ReadWriter such as from a net.Conn
func (Stream) DecodeReadFull ¶
DecodeReadFull returns decoded (little endian) data of len(data), or what's left of the Stream if there is less data remaining available for the stream.
func (Stream) GetPacketStream ¶
func (s Stream) GetPacketStream() (PacketStream, int, error)
GetPacketStream reads the next VarInt, and creates a PacketStream limited by the VarInt representing the entirety of the packet.
func (Stream) ReadBoolean ¶
ReadBoolean reads the next byte as a boolean from the stream.
func (Stream) ReadFloat32 ¶
ReadFloat32 reads the next 4 bytes as a float32 (a single-precision float) from the stream.
func (Stream) ReadFloat64 ¶
ReadFloat64 reads the next 8 bytes as a float64 (a double-precision float) from the stream.
func (Stream) ReadFull ¶
ReadFull returns raw data (big endian) of len(data), or what's left of the Stream if there is less data remaining available for the stream.
func (Stream) ReadSignedByte ¶
ReadSignedByte reads the next byte as a signed byte (int8) from the stream.
func (Stream) ReadString ¶
ReadString reads the next ReadVarInt bytes + the length of the VarInt and returns the string data from the stream.
func (Stream) ReadUInt16 ¶
ReadUInt16 reads the next 2 bytes as an uint16 (an unsigned short) from the stream.
func (Stream) ReadVarInt ¶
ReadVarInt reads the next couple of bytes which corresponds to a VarInt as an int from the stream.
func (Stream) ReadVarInt64 ¶
ReadVarInt64 reads the next couple of bytes which corresponds to a VarInt as an int64 from the stream.
This code is taken from thinkofdeath's steven (github.com/thinkofdeath/steven).
func (Stream) WritePacket ¶
WritePacket writes the length of the Packet as a VarInt, and the Packet's Data (payload) to the stream.