protocol

package
v0.0.0-...-f92d382 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2016 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package protocol implements functions for reading, writing, decoding, and encoding data for the Minecraft protocol.

Index

Constants

This section is empty.

Variables

View Source
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

func NewPacketWithID(id int) *Packet

NewPacketWithID returns a new Packet with the Id written to the start of the Packet.

func (*Packet) Write

func (p *Packet) Write(data []byte) (int, error)

Write writes arbitrary bytes to the Packet.

func (*Packet) WriteBoolean

func (p *Packet) WriteBoolean(data bool)

WriteBoolean writes a boolean to the Packet.

func (*Packet) WriteByte

func (p *Packet) WriteByte(data byte) error

WriteByte writes a single byte to the Packet.

func (*Packet) WriteFloat32

func (p *Packet) WriteFloat32(data float32)

WriteFloat32 writes a float32 (a single-precision float) to the Packet.

func (*Packet) WriteFloat64

func (p *Packet) WriteFloat64(data float64)

WriteFloat64 writes a float64 (a double-precision float) to the Packet.

func (*Packet) WriteInt16

func (p *Packet) WriteInt16(data int16)

WriteInt16 writes an int16 (a short) to the Packet.

func (*Packet) WriteInt32

func (p *Packet) WriteInt32(data int32)

WriteInt32 writes an int32 to the Packet.

func (*Packet) WriteInt64

func (p *Packet) WriteInt64(data int64)

WriteInt64 writes an int64 (a long) to the Packet.

func (*Packet) WriteSignedByte

func (p *Packet) WriteSignedByte(data int8)

WriteSignedByte writes an int8 to the Packet.

func (*Packet) WriteString

func (p *Packet) WriteString(data string)

WriteString writes a VarInt which is the length of the string, and the string itself to the Packet.

func (*Packet) WriteUInt16

func (p *Packet) WriteUInt16(data uint16)

WriteUInt16 writes an uint16 (an unsigned short) to the Packet.

func (*Packet) WriteVarInt

func (p *Packet) WriteVarInt(data int)

WriteVarInt writes an int as a VarInt to the Packet.

func (*Packet) WriteVarInt64

func (p *Packet) WriteVarInt64(data int64)

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

func (s Stream) DecodeReadFull(data []byte) error

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

func (s Stream) ReadBoolean() (bool, error)

ReadBoolean reads the next byte as a boolean from the stream.

func (Stream) ReadByte

func (s Stream) ReadByte() (byte, error)

ReadByte reads the next single byte from the stream.

func (Stream) ReadFloat32

func (s Stream) ReadFloat32() (float32, error)

ReadFloat32 reads the next 4 bytes as a float32 (a single-precision float) from the stream.

func (Stream) ReadFloat64

func (s Stream) ReadFloat64() (float64, error)

ReadFloat64 reads the next 8 bytes as a float64 (a double-precision float) from the stream.

func (Stream) ReadFull

func (s Stream) ReadFull(data []byte) error

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) ReadInt16

func (s Stream) ReadInt16() (int16, error)

ReadInt16 reads the next 2 bytes as an int16 (a short) from the stream.

func (Stream) ReadInt32

func (s Stream) ReadInt32() (int32, error)

ReadInt32 reads the next 4 bytes as an int32 from the stream.

func (Stream) ReadInt64

func (s Stream) ReadInt64() (int64, error)

ReadInt64 reads the next 8 bytes as an int64 (a long) from the stream.

func (Stream) ReadSignedByte

func (s Stream) ReadSignedByte() (int8, error)

ReadSignedByte reads the next byte as a signed byte (int8) from the stream.

func (Stream) ReadString

func (s Stream) ReadString() (string, error)

ReadString reads the next ReadVarInt bytes + the length of the VarInt and returns the string data from the stream.

func (Stream) ReadUInt16

func (s Stream) ReadUInt16() (uint16, error)

ReadUInt16 reads the next 2 bytes as an uint16 (an unsigned short) from the stream.

func (Stream) ReadVarInt

func (s Stream) ReadVarInt() (int, error)

ReadVarInt reads the next couple of bytes which corresponds to a VarInt as an int from the stream.

func (Stream) ReadVarInt64

func (s Stream) ReadVarInt64() (int64, error)

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

func (s Stream) WritePacket(p *Packet) error

WritePacket writes the length of the Packet as a VarInt, and the Packet's Data (payload) to the stream.

Jump to

Keyboard shortcuts

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