Documentation
¶
Overview ¶
codec package for encoding/decoding messages over the wire this exists so that we use networking through easy-to-use interfaces, and that when this file changes
Index ¶
- Constants
- Variables
- func Decode(buf []byte, vptr interface{}) (err error)
- func Encode(buf *bytes.Buffer, b []byte, vptr interface{}) (n int, err error)
- type Codec
- func (c *Codec) Close() error
- func (c *Codec) Decode(b []byte, vptr interface{}) (err error)
- func (c *Codec) DecodeFloat(b []byte) float64
- func (c *Codec) DecodeUint64(b []byte) uint64
- func (c *Codec) EncodeFloat(i float64) []byte
- func (c *Codec) EncodeUint64(i uint64) []byte
- func (c *Codec) New(conn net.Conn) *Codec
- func (c *Codec) Read(b []byte) (typ types.Type, reqid uint64, n int, err error)
- func (c *Codec) Write(v Typer) (n int, err error)
- type Encodable
- type Typer
Constants ¶
const DefaultMaxSize = 1024
DefaultMaxSize is what new codecs have
Variables ¶
var Debug = os.Getenv("DEBUG") != ""
Debug ...
var ErrConn = errors.New("nil conn")
ErrConn no connection
var ErrShort = errors.New("short error")
ErrShort short or small
var ErrSizeBig = errors.New("big error")
ErrSizebig too big
var ErrZeroType = errors.New("zero type")
var LogTypeStringer func(b byte) string
Functions ¶
Types ¶
type Codec ¶
Codec to encode/decode network packets uniformly across clients and servers One codec per connection One codec should be writing to a single connection at a time One codec should be reading from a single connection at a time This should be easy enough to work with
func NewCodec ¶
func NewCodec(endian binary.ByteOrder, conn io.ReadWriteCloser) *Codec
NewCodec starts everything.. If server, conn can be nil, in which case we use New() for each conn
func (*Codec) Close ¶
Close closes the network connection. If there is no conn, ErrConn will be returned.
func (*Codec) DecodeFloat ¶
func (*Codec) DecodeUint64 ¶
func (*Codec) EncodeFloat ¶
func (*Codec) EncodeUint64 ¶
func (*Codec) New ¶
New copies a codec but with a new connection. Server uses this for each new connection.
type Encodable ¶
type Encodable interface { Encode(b []byte) (int, error) // should return an error if buffer is too small //Decode(b []byte) error // should return first error encountered along the way Type() types.Type // returns 0-255, sent as prefix EncodeTo(w io.Writer) (int, error) }
Encodable is an easy to implement interface that can be sent over the wire