using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; namespace CScript.Net { public class QuicPackageHandler { private MemoryStream _stream = new MemoryStream(4096000); private int _readOffset = 0; private string _startSign;//#号表示一个数据的开始 private bool _startWriteSteam = false; public QuicPackageHandler() { } public void ReceiveData(byte[] data, int offset, int count) { if (!_startWriteSteam) { while (_readOffset + 13 < count) { _startSign = System.Text.Encoding.UTF8.GetString(data, _readOffset, 1); int packageDataLen = BitConverter.ToInt32(data, _readOffset + 9); if (_startSign == "#" && packageDataLen >= 0) { _startWriteSteam = true; break; } else { _readOffset++; } } } else { if (_stream.Position + count > _stream.Capacity) { throw new Exception("PackageHandler write buffer overflow"); } _stream.Write(data, offset, count); //ParsePackage(); } } } }