types

package
v0.0.0-...-fe38a42 Latest Latest
Warning

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

Go to latest
Published: May 22, 2015 License: MIT Imports: 5 Imported by: 3

Documentation

Overview

Package containing the types and errors used by all other packages.

Index

Constants

This section is empty.

Variables

View Source
var VarintMinimumSizeError = errors.New("varint not encoded with minimum size")

Number encoded as varint does not use minimum bytes for representation.

Functions

func DeserializeTo

func DeserializeTo(to Serializer, raw []byte) error

A common function for deserializing a byte array into an instance of the object using the defined DeserializeReader method.

Types

type DeserializeFailedError

type DeserializeFailedError string

Deserialization of an object failed. Used by Deserialize and DeserializeReader methods of the NetworkSerializer interface.

func (DeserializeFailedError) Error

func (e DeserializeFailedError) Error() string

type NotEnoughBytesError

type NotEnoughBytesError int

Read failed because of not enough bytes.

func (NotEnoughBytesError) Error

func (e NotEnoughBytesError) Error() string

type Serializer

type Serializer interface {
	// Serialize the object into bytes
	Serialize() []byte
	// Deserialize the object from io.Reader
	DeserializeReader(io.Reader) error
}

Interface defined for every message and serializable type.

type Varint

type Varint uint64

Integer can be encoded depending on the represented value to save space. Variable length integers always precede an array/vector of a type of data that may vary in length. Varints MUST use the minimum possible number of bytes to encode a value.

For example: the value 6 can be encoded with one byte therefore a varint that uses three bytes to encode the value 6 is malformed and the decoding task must be aborted.

func (*Varint) DeserializeReader

func (i *Varint) DeserializeReader(b io.Reader) error

func (Varint) Serialize

func (i Varint) Serialize() []byte

type VarintList

type VarintList []Varint

n integers can be stored using n+1 variable length integers where the first var_int equals n.

func (*VarintList) DeserializeReader

func (i *VarintList) DeserializeReader(b io.Reader) error

func (VarintList) Serialize

func (i VarintList) Serialize() []byte

type Varstring

type Varstring string

Variable length string can be stored using a variable length integer followed by the string itself.

func (*Varstring) DeserializeReader

func (str *Varstring) DeserializeReader(buf io.Reader) error

func (Varstring) Serialize

func (str Varstring) Serialize() []byte

Jump to

Keyboard shortcuts

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