msg

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgId_Login    byte = iota
	MsgId_LoginRet      //1

	MsgId_CreateEntity //2
	MsgId_RemoveEntity //3

	MsgId_EntityMsg    //4
	MsgId_EntityRPCMsg //5
	MsgId_SrvMsg       //6
	MsgId_ClientMsg    //7

	MsgId_Tick  //8
	MsgId_Error //9

	MsgId_SyncEntity         //10
	MsgId_ServerInfo         //11
	MsgId_NewClientPeer      //12
	MsgId_SetClientPeerId    //13
	MsgId_PublicEntityMsg    //4
	MsgId_PublicEntityRPCMsg //4
	MsgId_RemoteCall         //4
)
View Source
const (
	ERRCODE_NONE uint16 = iota
	ERRCODE_NOT_LOGIN
	ERRCODE_ERR_LOGIN
	ERRCODE_ERR_PASSWORD
	ERRCODE_ERR_REDIS
	ERRCODE_TOKEN_NOT_EXISTS
	ERRCODE_CREATE_ENTITY_FAILED
	ERRCODE_ALREADY_EXISTS
)
View Source
const HeaderSize = 16
View Source
const MaxSize = 1 << 13

MaxSize is the supported maximum size

Variables

View Source
var EtypeVerifyMap map[uint16]uint16
View Source
var MidVerifyMap map[uint16]uint16

Functions

func DecryptData

func DecryptData(buf []byte) []byte

decryptData 解密算法

func EncryptData

func EncryptData(buf []byte) []byte

encryptData 加密算法

func PackMsg

func PackMsg(msgid byte, flag byte, databuff []byte) []byte

func PutRecvStream

func PutRecvStream(sm Stream)

func PutSendStream

func PutSendStream(sm Stream)

func PutStream

func PutStream(sm Stream)

func ReadMsg

func ReadMsg(reader io.Reader) (uint16, byte, byte, uint64, []byte, []byte, error)

return (size, flag, msgid, fid, databuff, rawbuff, err) 可以优化这边的读取,读取到一个大的buff中 1.先读取headerSize个字节到buff中,然后解析出header 2.根据解析出来的数据size,将数据读取到buff中

func WriteMsgHeader

func WriteMsgHeader(msgid byte, flag byte, fid uint64, bs *stream.ByteStream)

Types

type IEntity

type IEntity interface {
	ID() uint64

	RegisterMethodId(id uint16, processer func(bs *RecvStream) error)
	//ForwardMsg(data []byte) error
	//ProcessMethod(id uint16, bs *RecvStream) error
	ProcessRpc(bs *RecvStream) error

	Marshal(bs *SendStream) error
	Unmarshal(bs *RecvStream) error
}

type LoginRetMsg

type LoginRetMsg struct {
	ErrorDesc   string `json:"error,omitempty"`
	ErrorCode   uint16 `json:"errorcode"`
	Eid         uint64 `json:"eid,string"`
	PeerId      uint64 `json:"peerid,string"`
	SrvPeerId   uint64 `json:"srvpeerid,string"`
	SrvPeerType byte   `json:"srvpeertype"`
	Uid         uint64 `json:"uid,string"`
	Account     string `json:"account,omitempty"`
	SrvAddr     string `json:"srvaddr,omitempty"`
	Token       string `json:"token,omitempty"`
}

type MsgObj

type MsgObj struct {
	Id            uint64
	MsgId         byte
	MsgSize       int16
	SerializeFunc func(*SendStream)
}

func GetMsgObj

func GetMsgObj(msgid byte, msgsize uint16) *MsgObj

type RecvStream

type RecvStream struct {
	// contains filtered or unexported fields
}

func GetRecvStream

func GetRecvStream(size uint16) *RecvStream

func (*RecvStream) DataSize

func (rs *RecvStream) DataSize() uint16

func (*RecvStream) Decode

func (rs *RecvStream) Decode() error

func (*RecvStream) DecompressAndDecrypt

func (rs *RecvStream) DecompressAndDecrypt() error

func (*RecvStream) Decrypt

func (rs *RecvStream) Decrypt() error

func (*RecvStream) DestPeer

func (rs *RecvStream) DestPeer() byte

func (*RecvStream) Eid

func (rs *RecvStream) Eid() uint64

func (*RecvStream) Etype

func (rs *RecvStream) Etype() uint16

func (*RecvStream) Flag

func (rs *RecvStream) Flag() byte

func (*RecvStream) GetBuff

func (rs *RecvStream) GetBuff() []byte

func (*RecvStream) GetHeader

func (rs *RecvStream) GetHeader() (destpeer byte, mid uint16, etype uint16, eid uint64)

func (*RecvStream) Mid

func (rs *RecvStream) Mid() uint16

func (*RecvStream) ReadBool

func (rs *RecvStream) ReadBool() (bool, error)

ReadBool 读bool

func (*RecvStream) ReadByte

func (rs *RecvStream) ReadByte() (byte, error)

ReadByte 读取一个字节

func (*RecvStream) ReadBytes

func (rs *RecvStream) ReadBytes() ([]byte, error)

ReadBytes 读取一个byte[]

func (*RecvStream) ReadFloat32

func (rs *RecvStream) ReadFloat32() (float32, error)

ReadFloat32 读取float32

func (*RecvStream) ReadFloat64

func (rs *RecvStream) ReadFloat64() (float64, error)

ReadFloat64 读取float64

func (*RecvStream) ReadInt16

func (rs *RecvStream) ReadInt16() (int16, error)

ReadInt16 读取一个int16

func (*RecvStream) ReadInt32

func (rs *RecvStream) ReadInt32() (int32, error)

ReadInt32 读取一个int32

func (*RecvStream) ReadInt64

func (rs *RecvStream) ReadInt64() (int64, error)

ReadInt64 读取一个int64

func (*RecvStream) ReadInt8

func (rs *RecvStream) ReadInt8() (int8, error)

ReadInt8 读取一个int8

func (*RecvStream) ReadString

func (rs *RecvStream) ReadString() (string, error)

ReadString 读取一个string

func (*RecvStream) ReadUint16

func (rs *RecvStream) ReadUint16() (uint16, error)

ReadUInt16 读取一个UInt16

func (*RecvStream) ReadUint32

func (rs *RecvStream) ReadUint32() (uint32, error)

ReadUInt32 读取一个Int

func (*RecvStream) ReadUint64

func (rs *RecvStream) ReadUint64() (uint64, error)

ReadUInt64 读取一个Uint64

func (*RecvStream) ReadUint64s

func (rs *RecvStream) ReadUint64s() ([]uint64, error)

func (*RecvStream) Recv

func (rs *RecvStream) Recv(r io.Reader) error

func (*RecvStream) Reset

func (rs *RecvStream) Reset()

func (*RecvStream) SetHeader

func (rs *RecvStream) SetHeader(destpeer byte, mid uint16, etype uint16, eid uint64)

func (*RecvStream) String

func (rs *RecvStream) String() string

func (*RecvStream) UnSerializeArgs

func (rs *RecvStream) UnSerializeArgs(funcref reflect.Value) ([]reflect.Value, error)

type SendStream

type SendStream struct {
	// contains filtered or unexported fields
}

func GetDefaultSendStream

func GetDefaultSendStream() *SendStream

func GetSendStream

func GetSendStream(size uint16) *SendStream

func (*SendStream) Clone

func (ss *SendStream) Clone() *SendStream

func (*SendStream) CompressAndEncrypt

func (ss *SendStream) CompressAndEncrypt() uint16

func (*SendStream) Encode

func (ss *SendStream) Encode() error

func (*SendStream) Encrypt

func (ss *SendStream) Encrypt() error

func (*SendStream) GetBuff

func (ss *SendStream) GetBuff() []byte

func (*SendStream) SerializeArgs

func (ss *SendStream) SerializeArgs(args ...interface{}) error

func (*SendStream) SetDataSize

func (ss *SendStream) SetDataSize(size uint16)

func (*SendStream) SetDestPeer

func (ss *SendStream) SetDestPeer(destpeer byte)

func (*SendStream) SetEid

func (ss *SendStream) SetEid(eid uint64)

func (*SendStream) SetEtype

func (ss *SendStream) SetEtype(etype uint16)

func (*SendStream) SetFlag

func (ss *SendStream) SetFlag(flag byte)

func (*SendStream) SetHeader

func (ss *SendStream) SetHeader(destpeer byte, mid, etype uint16, eid uint64)

func (*SendStream) SetMid

func (ss *SendStream) SetMid(msgid uint16)

func (*SendStream) String

func (ss *SendStream) String() string

func (*SendStream) WriteBool

func (ss *SendStream) WriteBool(v bool) error

WriteBool 写bool, 1代表true, 0代表false

func (*SendStream) WriteByte

func (ss *SendStream) WriteByte(v byte) error

WriteByte 写字节

func (*SendStream) WriteBytes

func (ss *SendStream) WriteBytes(v []byte) error

WriteBytes 写[]byte

func (*SendStream) WriteFloat32

func (ss *SendStream) WriteFloat32(f float32) error

WriteFloat32 写Float32

func (*SendStream) WriteFloat64

func (ss *SendStream) WriteFloat64(f float64) error

WriteFloat64 写Float64

func (*SendStream) WriteInt16

func (ss *SendStream) WriteInt16(v int16) error

WriteInt16 写Int16

func (*SendStream) WriteInt32

func (ss *SendStream) WriteInt32(v int32) error

WriteInt32 写Int32

func (*SendStream) WriteInt64

func (ss *SendStream) WriteInt64(v int64) error

WriteInt64 写Int64

func (*SendStream) WriteInt8

func (ss *SendStream) WriteInt8(v int8) error

WriteInt8 写Int8

func (*SendStream) WriteString

func (ss *SendStream) WriteString(v string) error

WriteString 写string

func (*SendStream) WriteUint16

func (ss *SendStream) WriteUint16(v uint16) error

WriteUInt16 写Uint16

func (*SendStream) WriteUint32

func (ss *SendStream) WriteUint32(v uint32) error

WriteUInt32 写Uint32

func (*SendStream) WriteUint64

func (ss *SendStream) WriteUint64(v uint64) error

WriteUInt64 写Uint64

func (*SendStream) WriteUint64s

func (ss *SendStream) WriteUint64s(v []uint64) error

func (*SendStream) WriteUint8

func (ss *SendStream) WriteUint8(v uint8) error

type Stream

type Stream interface {
	GetBuff() []byte
}

type UserTokenInfo

type UserTokenInfo struct {
	Uid         uint64 `json:"uid"`
	Eid         uint64 `json:"eid"`
	PeerId      uint64 `json:"peerid"`
	SrvPeerId   uint64 `json:"srvpeerid"`
	SrvPeerType byte   `json:"srvpeertype"`
	Account     string `json:"account"`
	Token       string `json:"token"`
	Addr        string `json:"addr"`
}

Jump to

Keyboard shortcuts

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