protected virtual void HandlePackage(byte[] buffer) { MemoryStream ms = new MemoryStream(buffer); CytarStreamReader cr = new CytarStreamReader(ms); var cid = cr.ReadInt32(); string apiName = cr.ReadString(); if (apiName == APIReturnHandlerAPI) { var returnID = cr.ReadInt32(); OnAPIReturn(returnID, ms); return; } else if (apiName == ErrorHandlerAPI) { OnErrorCallback(cid, cr.ReadObject <RemoteException>()); return; } try { var(result, isVoid) = CallAPI(apiName, ms); CallRemoteAPI(APIReturnHandlerAPI, cid, result); } catch (Exception ex) { CallRemoteAPI(ErrorHandlerAPI, new RemoteException(ex.Message)); } }
internal virtual byte[] ReadPackage(int sizeLimit = int.MaxValue) { lock (NetworkSession.InputStream) { CytarStreamReader cr = new CytarStreamReader(NetworkSession.InputStream); var size = cr.ReadInt32(); if (size > sizeLimit) { throw new DataSizeException(sizeLimit, size); } return(cr.ReadBytes(size)); } }