zproto

package
v0.0.0-...-e41513e Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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
)
View Source
const (
	RES_STATE_NONE  = 0x00
	RES_STATE_OK    = 0x01
	RES_STATE_ERROR = 0x02
)
View Source
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 Watcher

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

type ZProto

type ZProto struct {
}

func (*ZProto) NewCodec

func (this *ZProto) NewCodec(rw io.ReadWriter) (net2.Codec, error)

type ZProtoAck

type ZProtoAck struct {
	ReceivedPackageIndex int
}

//////////////////////////////////////////////////////////////////////////////

func (*ZProtoAck) Decode

func (m *ZProtoAck) Decode(dbuf *bytes2.BufferInput) error

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 ZProtoClientCallBack interface {
	OnNewClient(client *net2.TcpClient)
	OnClientMessageArrived(client *net2.TcpClient, md *ZProtoMetadata, sessionId, messageId uint64, seqNo uint32, msg MessageBase) error
	OnClientClosed(client *net2.TcpClient)
	OnClientTimer(client *net2.TcpClient)
}

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

type ZProtoDrop struct {
	MessageId    int64
	ErrorCode    int32
	ErrorMessage string
}

//////////////////////////////////////////////////////////////////////////////

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 (*ZProtoHandshakeMessage) Encode

func (*ZProtoHandshakeMessage) String

func (m *ZProtoHandshakeMessage) String() string

type ZProtoHandshakeReq

type ZProtoHandshakeReq struct {
	ProtoRevision int
	RandomBytes   [32]byte
}

//////////////////////////////////////////////////////////////////////////////

func (*ZProtoHandshakeReq) Decode

func (m *ZProtoHandshakeReq) Decode(dbuf *bytes2.BufferInput) error

func (*ZProtoHandshakeReq) Encode

func (m *ZProtoHandshakeReq) Encode(x *bytes2.BufferOutput)

type ZProtoHandshakeRes

type ZProtoHandshakeRes struct {
	ProtoRevision int
	Sha1          [32]byte
}

//////////////////////////////////////////////////////////////////////////////

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

type ZProtoPong struct {
	MessageId uint64
	PingId    int64
}

//////////////////////////////////////////////////////////////////////////////

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

type ZProtoRedirect struct {
	Host    string
	Port    int
	Timeout int
}

////////////////////////////////////////////////////////////////////////////// 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

type ZProtoRpcFloodWait struct {
	RequestMessageId int64
	Delay            int
}

//////////////////////////////////////////////////////////////////////////////

func (*ZProtoRpcFloodWait) Decode

func (m *ZProtoRpcFloodWait) Decode(dbuf *bytes2.BufferInput) error

func (*ZProtoRpcFloodWait) Encode

func (m *ZProtoRpcFloodWait) Encode(x *bytes2.BufferOutput)

type ZProtoRpcInternalError

type ZProtoRpcInternalError struct {
	RequestMessageId int64
	CanTryAgain      bool
	TryAgainDelay    int
}

//////////////////////////////////////////////////////////////////////////////

func (*ZProtoRpcInternalError) Decode

func (*ZProtoRpcInternalError) Encode

type ZProtoRpcOk

type ZProtoRpcOk struct {
	RequestMessageId int64
	MethodResponseId string
	Body             []byte
}

//////////////////////////////////////////////////////////////////////////////

func (*ZProtoRpcOk) Decode

func (m *ZProtoRpcOk) Decode(dbuf *bytes2.BufferInput) error

func (*ZProtoRpcOk) Encode

func (m *ZProtoRpcOk) Encode(x *bytes2.BufferOutput)

type ZProtoRpcRequest

type ZProtoRpcRequest struct {
	MethodId string
	Body     []byte
}

//////////////////////////////////////////////////////////////////////////////

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 (*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

type ZProtoSessionClientClosed struct {
	ConnType  int
	SessionId uint64
	AuthKeyId int64
}

/////////////////////////////////////////////////////////////////////////////////////////

func (*ZProtoSessionClientClosed) Decode

func (*ZProtoSessionClientClosed) Encode

func (*ZProtoSessionClientClosed) String

func (m *ZProtoSessionClientClosed) String() string

type ZProtoSessionClientNew

type ZProtoSessionClientNew struct {
	// proto int32
	ConnType  int
	SessionId uint64
	AuthKeyId int64
}

/////////////////////////////////////////////////////////////////////////////////////////

func (*ZProtoSessionClientNew) Decode

func (*ZProtoSessionClientNew) Encode

func (*ZProtoSessionClientNew) String

func (m *ZProtoSessionClientNew) String() string

type ZProtoSessionData

type ZProtoSessionData struct {
	ConnType   int
	SessionId  uint64
	MtpRawData []byte
}

/////////////////////////////////////////////////////////////////////////////////////////

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

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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