msglib

package
v0.0.0-...-e5e1c34 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MT_NULL   byte = 1
	MT_BOOL   byte = 2
	MT_BYTE   byte = 3
	MT_I16    byte = 4
	MT_I32    byte = 5
	MT_I64    byte = 6
	MT_FLOAT  byte = 7
	MT_DOUBLE byte = 8
	MT_BINARY byte = 9
	MT_STRING byte = 10
	MT_STRUCT byte = 11
	MT_MAP    byte = 12
	MT_LIST   byte = 13
	MT_SET    byte = 14
)

Variables

View Source
var MsgCodec = websocket.Codec{msglibMarshal, msglibUnmarshal}

MsgCodec is a codec to send/receive MsgLib data in a frame from a WebSocket connection.

Example:

type T struct {
	Msg string `msglib:"1"`
	Count int `msglib:"2"`
}

// receive Msglib type T
var data T
msglib.MsgCodec.Receive(ws, &data)

// send MsgLib type T
msglib.MsgCodec.Send(ws, data)

Functions

func DecodeStruct

func DecodeStruct(reader io.Reader, proto IMProto, val interface{}) (err error)

func Deserialize

func Deserialize(payload []byte, data interface{}) (err error)

func EncodeStruct

func EncodeStruct(w io.Writer, proto IMProto, data interface{}) (err error)

func Serialize

func Serialize(data interface{}) (payload []byte, err error)

func SkipValue

func SkipValue(reader io.Reader, proto IMProto, msgtype byte) error

Types

type IMProto

type IMProto interface {
	ReadStructBegin(reader io.Reader) (*MStruct, error)

	ReadFieldBegin(reader io.Reader) (*MField, error)

	ReadMapBegin(reader io.Reader) (*MMap, error)

	ReadListBegin(reader io.Reader) (*MList, error)

	ReadSetBegin(reader io.Reader) (*MSet, error)

	ReadBool(reader io.Reader) (bool, error)

	ReadByte(reader io.Reader) (byte, error)

	ReadI16(reader io.Reader) (int16, error)

	ReadI32(reader io.Reader) (int32, error)

	ReadI64(reader io.Reader) (int64, error)

	ReadFloat32(reader io.Reader) (float32, error)

	ReadFloat64(reader io.Reader) (float64, error)

	ReadBinary(reader io.Reader) ([]byte, error)

	ReadString(reader io.Reader) (string, error)

	WriteStructBegin(writer io.Writer, marker *MStruct) error

	WriteFieldBegin(writer io.Writer, marker *MField) error

	WriteFieldStop(writer io.Writer) error

	WriteMapBegin(writer io.Writer, marker *MMap) error

	WriteListBegin(writer io.Writer, marker *MList) error

	WriteSetBegin(writer io.Writer, marker *MSet) error

	WriteBool(writer io.Writer, data bool) error

	WriteByte(writer io.Writer, data byte) error

	WriteI16(writer io.Writer, data int16) error

	WriteI32(writer io.Writer, data int32) error

	WriteI64(writer io.Writer, data int64) error

	WriteFloat32(writer io.Writer, data float32) error

	WriteFloat64(writer io.Writer, data float64) error

	WriteBinary(writer io.Writer, data []byte) error

	WriteString(writer io.Writer, str string) error
}

func NewBinaryProto

func NewBinaryProto() IMProto

type MField

type MField struct {
	Name string
	Type byte
	ID   int
}

type MList

type MList struct {
	ElementType byte
	Count       int
}

type MMap

type MMap struct {
	KeyType   byte
	ValueType byte
	Count     int
}

type MSet

type MSet struct {
	ElementType byte
	Count       int
}

type MStruct

type MStruct struct {
	Name string
}

type UnsupportedTypeError

type UnsupportedTypeError struct {
	Type reflect.Type
}

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

type UnsupportedValueError

type UnsupportedValueError struct {
	Value   reflect.Value
	Message string
}

func (*UnsupportedValueError) Error

func (e *UnsupportedValueError) Error() string

Jump to

Keyboard shortcuts

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