///------------ protected void _onData(byte[] data) { try { ByteBuffer buffer = new ByteBuffer(data); NetMessage netMessage = null; /// Read the headerType first to determine which message class to use buffer.position = NetMessage.LEN_SIZE; short headerType = buffer.FReadByte(); buffer.position = 0; if (HeaderType.RPCCall == headerType) { netMessage = new NetRPCCall(); } else if (HeaderType.RPCReturn == headerType) { netMessage = new _NetRPCReturn(); } else if (HeaderType.Notify == headerType) { netMessage = new NetNotify(); } else { throw NetMessage.INVALID_HEADER_TYPE; } netMessage.Deserialize(buffer); bool needFurtherProcess = true; if (NetMessageFilter != null) { needFurtherProcess = NetMessageFilter(netMessage); } if (needFurtherProcess) { if (HeaderType.RPCCall == headerType) { Debugger.Assert(false, "Has not implement!"); } else if (HeaderType.RPCReturn == headerType) { _netRPCComponent._OnRPCReturn(netMessage as _NetRPCReturn); } else if (HeaderType.Notify == headerType) { int handlerCount = _messageDispatcher.DispatchEvent(netMessage); if (0 == handlerCount) { Debugger.LogWarning("No message handler for message type: " + netMessage.type); } } else { Debugger.Assert(false); } } } catch (Exception e) { _onFatalError(e); } }
public void SendNetNotify(NetNotify netNotify) { this.SendNetMessage(netNotify); }