Documentation ¶
Index ¶
- Constants
- func EncodeMessage(msg MessageBase) []byte
- func SendMessageByClient(client *net2.TcpClient, md *ZProtoMetadata, msg MessageBase) error
- func SendMessageByConn(conn *net2.TcpConnection, md *ZProtoMetadata, msg MessageBase) error
- type HandshakeState
- type MessageBase
- type Watcher
- type ZProto
- type ZProtoAck
- type ZProtoClient
- func (c *ZProtoClient) OnClientClosed(client *net2.TcpClient)
- func (c *ZProtoClient) OnClientDataArrived(client *net2.TcpClient, msg interface{}) error
- func (c *ZProtoClient) OnClientTimer(client *net2.TcpClient)
- func (c *ZProtoClient) OnNewClient(client *net2.TcpClient)
- func (c *ZProtoClient) Pause()
- func (c *ZProtoClient) SendKetamaMessage(name, key string, md *ZProtoMetadata, msg MessageBase, f func(addr string)) error
- func (c *ZProtoClient) SendMessage(name string, md *ZProtoMetadata, msg MessageBase) error
- func (c *ZProtoClient) SendMessageToAddress(name, addr string, md *ZProtoMetadata, msg MessageBase) error
- func (c *ZProtoClient) Serve()
- func (c *ZProtoClient) Stop()
- type ZProtoClientCallBack
- type ZProtoClientConfig
- type ZProtoCodec
- type ZProtoDrop
- type ZProtoHandshakeMessage
- type ZProtoHandshakeReq
- type ZProtoHandshakeRes
- type ZProtoMarsSignal
- type ZProtoMessage
- type ZProtoMessageAck
- type ZProtoMetadata
- type ZProtoPing
- type ZProtoPong
- type ZProtoRawPayload
- type ZProtoRedirect
- type ZProtoRpcError
- type ZProtoRpcFloodWait
- type ZProtoRpcInternalError
- type ZProtoRpcOk
- type ZProtoRpcRequest
- type ZProtoServer
- func (s *ZProtoServer) OnConnectionClosed(conn *net2.TcpConnection)
- func (s *ZProtoServer) OnConnectionDataArrived(conn *net2.TcpConnection, msg interface{}) error
- func (s *ZProtoServer) OnNewConnection(conn *net2.TcpConnection)
- func (s *ZProtoServer) Pause()
- func (s *ZProtoServer) SendMessageByConnID(connID uint64, md *ZProtoMetadata, msg MessageBase) error
- func (s *ZProtoServer) Serve()
- func (s *ZProtoServer) Stop()
- type ZProtoServerCallback
- type ZProtoServerConfig
- type ZProtoSessionClientClosed
- type ZProtoSessionClientNew
- type ZProtoSessionData
- type ZProtoSyncData
Constants ¶
const ( PROTO = 0xFF00 PING = 0x0100 PONG = 0x0200 DROP = 0x0300 REDIRECT = 0x0400 ACK = 0x0500 HANDSHAKE_REQ = 0x0600 HANDSHAKE_RSP = 0x0700 MARS_SIGNAL = 0x0800 MESSAGE_ACK = 0x0001 RPC_REQUEST = 0x000F RPC_OK = 0x0010 RPC_ERROR = 0x0011 RPC_FLOOD_WAIT = 0x0012 RPC_INTERNAL_ERROR = 0x0013 PUSH = 0x0014 )
const ( STATE_ERROR = 0x0000 STATE_CONNECTED2 = 0x0100 STATE_HANDSHAKE = 0x0200 STATE_pq = 0x0201 STATE_pq_res = 0x0202 STATE_pq_ack = 0x0203 STATE_DH_params = 0x0204 STATE_DH_params_res = 0x0205 STATE_DH_params_ack = 0x0206 STATE_dh_gen = 0x0207 STATE_dh_gen_res = 0x0208 STATE_dh_gen_ack = 0x0209 STATE_AUTH_KEY = 0x0300 )
const ( RES_STATE_NONE = 0x00 RES_STATE_OK = 0x01 RES_STATE_ERROR = 0x02 )
const ( SESSION_HANDSHAKE = 0xFF01 SESSION_SESSION_DATA = 0xFF02 SYNC_DATA = 0xFF03 SESSION_SESSION_CLIENT_NEW = 0xFF04 SESSION_SESSION_CLIENT_CLOSED = 0xFF05 )
Variables ¶
This section is empty.
Functions ¶
func EncodeMessage ¶
func EncodeMessage(msg MessageBase) []byte
func SendMessageByClient ¶
func SendMessageByClient(client *net2.TcpClient, md *ZProtoMetadata, msg MessageBase) error
/////////////////////////////////////////////////////////////////////////////////////////////
func SendMessageByConn ¶
func SendMessageByConn(conn *net2.TcpConnection, md *ZProtoMetadata, msg MessageBase) error
/////////////////////////////////////////////////////////////////////////////////////////////
Types ¶
type HandshakeState ¶
type HandshakeState struct { State int // 状态 ResState int // 后端握手返回的结果 Ctx []byte // 握手上下文数据,透传给后端 }
/////////////////////////////////////////////////////////////////////////////////////////
func (*HandshakeState) Decode ¶
func (m *HandshakeState) Decode(dbuf *bytes2.BufferInput) error
func (*HandshakeState) Encode ¶
func (m *HandshakeState) Encode(x *bytes2.BufferOutput)
func (*HandshakeState) String ¶
func (m *HandshakeState) String() string
type MessageBase ¶
type MessageBase interface { Encode(x *bytes2.BufferOutput) Decode(dbuf *bytes2.BufferInput) error }
func DecodeMessage ¶
func DecodeMessage(buf []byte) (MessageBase, error)
/////////////////////////////////////////////////////////////////////////////////////////////
func DecodeMessageByBuffer ¶
func DecodeMessageByBuffer(dbuf *bytes2.BufferInput) (MessageBase, error)
func NewZProtoMessage ¶
func NewZProtoMessage(msgType uint32) MessageBase
type ZProtoAck ¶
type ZProtoAck struct {
ReceivedPackageIndex int
}
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoAck) Encode ¶
func (m *ZProtoAck) Encode(x *bytes2.BufferOutput)
type ZProtoClient ¶
type ZProtoClient struct {
// contains filtered or unexported fields
}
func NewZProtoClient ¶
func NewZProtoClient(protoName string, conf *ZProtoClientConfig, cb ZProtoClientCallBack) *ZProtoClient
func (*ZProtoClient) OnClientClosed ¶
func (c *ZProtoClient) OnClientClosed(client *net2.TcpClient)
func (*ZProtoClient) OnClientDataArrived ¶
func (c *ZProtoClient) OnClientDataArrived(client *net2.TcpClient, msg interface{}) error
func (*ZProtoClient) OnClientTimer ¶
func (c *ZProtoClient) OnClientTimer(client *net2.TcpClient)
func (*ZProtoClient) OnNewClient ¶
func (c *ZProtoClient) OnNewClient(client *net2.TcpClient)
/////////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoClient) Pause ¶
func (c *ZProtoClient) Pause()
func (*ZProtoClient) SendKetamaMessage ¶
func (c *ZProtoClient) SendKetamaMessage(name, key string, md *ZProtoMetadata, msg MessageBase, f func(addr string)) error
func (*ZProtoClient) SendMessage ¶
func (c *ZProtoClient) SendMessage(name string, md *ZProtoMetadata, msg MessageBase) error
func (*ZProtoClient) SendMessageToAddress ¶
func (c *ZProtoClient) SendMessageToAddress(name, addr string, md *ZProtoMetadata, msg MessageBase) error
func (*ZProtoClient) Serve ¶
func (c *ZProtoClient) Serve()
/////////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoClient) Stop ¶
func (c *ZProtoClient) Stop()
type ZProtoClientCallBack ¶
type ZProtoClientConfig ¶
type ZProtoClientConfig struct {
Clients []net2.ClientConfig
}
type ZProtoCodec ¶
type ZProtoCodec struct {
// contains filtered or unexported fields
}
func (*ZProtoCodec) Close ¶
func (c *ZProtoCodec) Close() error
func (*ZProtoCodec) Receive ¶
func (c *ZProtoCodec) Receive() (interface{}, error)
func (*ZProtoCodec) Send ¶
func (c *ZProtoCodec) Send(msg interface{}) error
type ZProtoDrop ¶
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoDrop) Decode ¶
func (m *ZProtoDrop) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoDrop) Encode ¶
func (m *ZProtoDrop) Encode(x *bytes2.BufferOutput)
type ZProtoHandshakeMessage ¶
type ZProtoHandshakeMessage struct { SessionId uint64 State *HandshakeState MTPRawData []byte }
/////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoHandshakeMessage) Decode ¶
func (m *ZProtoHandshakeMessage) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoHandshakeMessage) Encode ¶
func (m *ZProtoHandshakeMessage) Encode(x *bytes2.BufferOutput)
func (*ZProtoHandshakeMessage) String ¶
func (m *ZProtoHandshakeMessage) String() string
type ZProtoHandshakeReq ¶
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoHandshakeReq) Decode ¶
func (m *ZProtoHandshakeReq) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoHandshakeReq) Encode ¶
func (m *ZProtoHandshakeReq) Encode(x *bytes2.BufferOutput)
type ZProtoHandshakeRes ¶
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoHandshakeRes) Decode ¶
func (m *ZProtoHandshakeRes) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoHandshakeRes) Encode ¶
func (m *ZProtoHandshakeRes) Encode(x *bytes2.BufferOutput)
type ZProtoMarsSignal ¶
type ZProtoMarsSignal struct { }
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoMarsSignal) Decode ¶
func (m *ZProtoMarsSignal) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoMarsSignal) Encode ¶
func (m *ZProtoMarsSignal) Encode(x *bytes2.BufferOutput)
type ZProtoMessage ¶
type ZProtoMessage struct { Metadata *ZProtoMetadata Message MessageBase // contains filtered or unexported fields }
func (*ZProtoMessage) Decode ¶
func (m *ZProtoMessage) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoMessage) Encode ¶
func (m *ZProtoMessage) Encode(x *bytes2.BufferOutput)
type ZProtoMessageAck ¶
type ZProtoMessageAck struct {
MessageIds []uint64
}
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoMessageAck) Decode ¶
func (m *ZProtoMessageAck) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoMessageAck) Encode ¶
func (m *ZProtoMessageAck) Encode(x *bytes2.BufferOutput)
type ZProtoMetadata ¶
type ZProtoMetadata struct { ServerId int ClientConnId uint64 ClientAddr string TraceId int64 SpanId int64 ReceiveTime int64 From string Options map[string]string // contains filtered or unexported fields }
///////////////////////////////////////////////////////////////
func (*ZProtoMetadata) Decode ¶
func (m *ZProtoMetadata) Decode(dbuf *bytes2.BufferInput) (err error)
func (*ZProtoMetadata) Encode ¶
func (m *ZProtoMetadata) Encode(x *bytes2.BufferOutput)
func (*ZProtoMetadata) String ¶
func (m *ZProtoMetadata) String() string
type ZProtoPing ¶
type ZProtoPing struct {
PingId int64
}
func (*ZProtoPing) Decode ¶
func (m *ZProtoPing) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoPing) Encode ¶
func (m *ZProtoPing) Encode(x *bytes2.BufferOutput)
//////////////////////////////////////////////////////////////////////////////
type ZProtoPong ¶
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoPong) Decode ¶
func (m *ZProtoPong) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoPong) Encode ¶
func (m *ZProtoPong) Encode(x *bytes2.BufferOutput)
type ZProtoRawPayload ¶
type ZProtoRawPayload struct {
Payload []byte
}
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoRawPayload) Decode ¶
func (m *ZProtoRawPayload) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoRawPayload) Encode ¶
func (m *ZProtoRawPayload) Encode(x *bytes2.BufferOutput)
func (*ZProtoRawPayload) String ¶
func (m *ZProtoRawPayload) String() string
type ZProtoRedirect ¶
////////////////////////////////////////////////////////////////////////////// RPC很少使用这条消息
func (*ZProtoRedirect) Decode ¶
func (m *ZProtoRedirect) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoRedirect) Encode ¶
func (m *ZProtoRedirect) Encode(x *bytes2.BufferOutput)
type ZProtoRpcError ¶
type ZProtoRpcError struct { RequestMessageId int64 ErrorCode int ErrorTag string UserMessage string CanTryAgain bool ErrorData []byte }
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoRpcError) Decode ¶
func (m *ZProtoRpcError) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoRpcError) Encode ¶
func (m *ZProtoRpcError) Encode(x *bytes2.BufferOutput)
type ZProtoRpcFloodWait ¶
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoRpcFloodWait) Decode ¶
func (m *ZProtoRpcFloodWait) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoRpcFloodWait) Encode ¶
func (m *ZProtoRpcFloodWait) Encode(x *bytes2.BufferOutput)
type ZProtoRpcInternalError ¶
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoRpcInternalError) Decode ¶
func (m *ZProtoRpcInternalError) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoRpcInternalError) Encode ¶
func (m *ZProtoRpcInternalError) Encode(x *bytes2.BufferOutput)
type ZProtoRpcOk ¶
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoRpcOk) Decode ¶
func (m *ZProtoRpcOk) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoRpcOk) Encode ¶
func (m *ZProtoRpcOk) Encode(x *bytes2.BufferOutput)
type ZProtoRpcRequest ¶
//////////////////////////////////////////////////////////////////////////////
func (*ZProtoRpcRequest) Decode ¶
func (m *ZProtoRpcRequest) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoRpcRequest) Encode ¶
func (m *ZProtoRpcRequest) Encode(x *bytes2.BufferOutput)
type ZProtoServer ¶
type ZProtoServer struct {
// contains filtered or unexported fields
}
func NewZProtoServer ¶
func NewZProtoServer(conf *ZProtoServerConfig, cb ZProtoServerCallback) *ZProtoServer
func (*ZProtoServer) OnConnectionClosed ¶
func (s *ZProtoServer) OnConnectionClosed(conn *net2.TcpConnection)
func (*ZProtoServer) OnConnectionDataArrived ¶
func (s *ZProtoServer) OnConnectionDataArrived(conn *net2.TcpConnection, msg interface{}) error
func (*ZProtoServer) OnNewConnection ¶
func (s *ZProtoServer) OnNewConnection(conn *net2.TcpConnection)
/////////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoServer) Pause ¶
func (s *ZProtoServer) Pause()
func (*ZProtoServer) SendMessageByConnID ¶
func (s *ZProtoServer) SendMessageByConnID(connID uint64, md *ZProtoMetadata, msg MessageBase) error
/////////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoServer) Serve ¶
func (s *ZProtoServer) Serve()
/////////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoServer) Stop ¶
func (s *ZProtoServer) Stop()
type ZProtoServerCallback ¶
type ZProtoServerCallback interface { OnServerNewConnection(conn *net2.TcpConnection) OnServerMessageDataArrived(conn *net2.TcpConnection, md *ZProtoMetadata, sessionId, messageId uint64, seqNo uint32, msg MessageBase) error OnServerConnectionClosed(conn *net2.TcpConnection) }
type ZProtoServerConfig ¶
type ZProtoServerConfig struct { Server net2.ServerConfig Discovery service_discovery.ServiceDiscoveryServerConfig }
type ZProtoSessionClientClosed ¶
/////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoSessionClientClosed) Decode ¶
func (m *ZProtoSessionClientClosed) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoSessionClientClosed) Encode ¶
func (m *ZProtoSessionClientClosed) Encode(x *bytes2.BufferOutput)
func (*ZProtoSessionClientClosed) String ¶
func (m *ZProtoSessionClientClosed) String() string
type ZProtoSessionClientNew ¶
/////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoSessionClientNew) Decode ¶
func (m *ZProtoSessionClientNew) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoSessionClientNew) Encode ¶
func (m *ZProtoSessionClientNew) Encode(x *bytes2.BufferOutput)
func (*ZProtoSessionClientNew) String ¶
func (m *ZProtoSessionClientNew) String() string
type ZProtoSessionData ¶
/////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoSessionData) Decode ¶
func (m *ZProtoSessionData) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoSessionData) Encode ¶
func (m *ZProtoSessionData) Encode(x *bytes2.BufferOutput)
func (*ZProtoSessionData) String ¶
func (m *ZProtoSessionData) String() string
type ZProtoSyncData ¶
type ZProtoSyncData struct {
SyncRawData []byte
}
/////////////////////////////////////////////////////////////////////////////////////////
func (*ZProtoSyncData) Decode ¶
func (m *ZProtoSyncData) Decode(dbuf *bytes2.BufferInput) error
func (*ZProtoSyncData) Encode ¶
func (m *ZProtoSyncData) Encode(x *bytes2.BufferOutput)
func (*ZProtoSyncData) String ¶
func (m *ZProtoSyncData) String() string