private void HandleData(byte[] _data) { using (Packet _packet = new Packet(_data)) { int _packetLength = _packet.ReadInt(); _data = _packet.ReadBytes(_packetLength); } TM.ExecuteOnMainThread(() => { using (Packet _packet = new Packet(_data)) { int _packetId = _packet.ReadInt(); packetHandlers[_packetId](_packet); } }); }
private bool HandleData(byte[] _data) { int _packetLength = 0; receivedData.SetBytes(_data); if (receivedData.UnreadLength() >= 4) { _packetLength = receivedData.ReadInt(); if (_packetLength <= 0) { return(true); } } while (_packetLength > 0 && _packetLength <= receivedData.UnreadLength()) { byte[] _packetBytes = receivedData.ReadBytes(_packetLength); TM.ExecuteOnMainThread(() => { using (Packet _packet = new Packet(_packetBytes)) { int _packetId = _packet.ReadInt(); packetHandlers[_packetId](_packet); } }); _packetLength = 0; if (receivedData.UnreadLength() >= 4) { _packetLength = receivedData.ReadInt(); if (_packetLength <= 0) { return(true); } } } if (_packetLength <= 1) { return(true); } return(false); }