/// <summary> /// /// </summary> /// <param name="bufferStream"></param> /// <returns></returns> public override RequestBaseInfo ResolvePackage(IBufferStream bufferStream) { var last = bufferStream.Buffers.Last(); var body = last.Array.Skip(last.Offset).Take(last.Count).ToArray(); return(new RequestBaseInfo(body)); }
/// <summary> /// 解包 /// </summary> /// <param name="bufferStream"></param> /// <returns></returns> public override ClientPackageInfo ResolvePackage(IBufferStream bufferStream) { ClientPackageInfo clientPackageInfo = new ClientPackageInfo(); try { String infoStr = Encoding.ASCII.GetString(bufferStream.Buffers, 0, base.HeaderSize); clientPackageInfo.MessageID = infoStr.Substring(0, 6).Trim(); clientPackageInfo.DateOfSending = infoStr.Substring(6, 8).Trim(); clientPackageInfo.TimeOfSending = infoStr.Substring(14, 6).Trim(); clientPackageInfo.Sender = infoStr.Substring(20, 2).Trim(); clientPackageInfo.Receiver = infoStr.Substring(22, 2).Trim(); clientPackageInfo.FunctionCode = infoStr.Substring(24, 1).Trim(); clientPackageInfo.Length = infoStr.Substring(25, 4).Trim(); int bodyLength = Convert.ToInt32(Encoding.ASCII.GetString(bufferStream.Buffers, 25, 4)) - base.HeaderSize; if (bodyLength > 0) { ArraySegment <byte> result = new ArraySegment <byte>(new byte[bodyLength]); bufferStream.Buffers.CopyTo(result, base.HeaderSize, bodyLength); clientPackageInfo.MessageBody = result.Array; } } catch (Exception ex) { LogHelper.Logger.Error("客户端ResolvePackage错误!", ex); clientPackageInfo = null; } return(clientPackageInfo); }
public override Packet ResolvePackage(IBufferStream bufferStream) { if (bufferStream.Length > Int32.MaxValue) { throw new ArgumentOutOfRangeException("Param too long"); // should never happen } string all = bufferStream.ReadString((int)bufferStream.Length, Encoding.UTF8); Packet p = new Packet(); if (all[0] == 'B') { p.broadcast = true; } else if (all[0] == 'M') { p.broadcast = false; } else { return(null); } int i = all.IndexOf(' '); if (i == -1) { return(null); } else { p.sender = all.Substring(1, i - 1); p.message = all.Substring(i + 1, all.Length - i - 3); } return(p); }
public override BufferedPackageInfo ResolvePackage(IBufferStream bufferStream) { var key = bufferStream.ReadString(4, Encoding.UTF8); bufferStream.Skip(2); return(new BufferedPackageInfo(key, bufferStream.Take((int)bufferStream.Length - 6))); }
protected override int GetBodyLengthFromHeader(IBufferStream stream, int size) { var reader = new BinaryReader(stream.GetCurrentStream()); var pSize = reader.ReadInt32(); return(pSize - DouyuPackageInfo.HeaderSize); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { byte[] array = bufferStream.Buffers.FirstOrDefault().ToArray(); int len = array[length - 2] + array[length - 1] * 256 + 2; return(len); }
/// <summary> /// Resolves the package. /// </summary> /// <param name="bufferStream">The received buffer stream.</param> /// <returns></returns> public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { var encoding = m_Encoding; var totalLen = (int)bufferStream.Length - SearchState.Mark.Length; return(new StringPackageInfo(bufferStream.ReadString(totalLen, encoding), m_StringParser)); }
public override BufferedPackageInfo ResolvePackage(IBufferStream bufferStream) { var header = bufferStream.Buffers.FirstOrDefault(); string key = Encoding.ASCII.GetString(header.Array, header.Offset, 4); return(new BufferedPackageInfo(key, bufferStream.Buffers)); }
public override EventPackageInfo ResolvePackage(IBufferStream bufferStream) { //log4j.Debug("bufferStream.Length: " + bufferStream.Length); //log4j.Debug("headerSize: " + this.HeaderSize); //log4j.Debug("bodySize: " + ((int)bufferStream.Length - this.HeaderSize)); //int key1 = bufferStream.Skip(4).ReadByte(); //int key2 = bufferStream.ReadByte(); //int key = key2 << 8 | key1; //int subKey1 = bufferStream.ReadByte(); //int subKey2 = bufferStream.ReadByte(); //int subKey = subKey2 << 8 | subKey1; EventPackageInfo ev = new EventPackageInfo(0, 0, ""); try { int key = bufferStream.Skip(4).ReadUInt16(true); // why read little indian?? int subKey = bufferStream.ReadUInt16(true); //log4j.Debug(string.Format("key: {0}, subKey: {1}", key, subKey)); string body = bufferStream.ReadString((int)bufferStream.Length - this.HeaderSize, Encoding.UTF8); ev = new EventPackageInfo(key, subKey, body); } catch (Exception ex) { log4j.Error("ResolvePackage: ", ex); } return(ev); }
public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { var line = bufferStream.ReadString((int)bufferStream.Length, Encoding.ASCII); var arr = line.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); return(new StringPackageInfo(arr[0], arr[1], new string[] { arr[1] })); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { var lenBytes = new byte[length]; bufferStream.Read(lenBytes, 0, length); return(BitConverter.ToInt32(lenBytes, 0)); }
/// <summary> /// Determines whether this instance [can resolve package] the specified package data. /// </summary> /// <param name="bufferStream">The received buffer stream.</param> /// <returns> /// <c>true</c> if this instance [can resolve package] the specified package data; otherwise, <c>false</c>. /// </returns> protected override bool CanResolvePackage(IBufferStream bufferStream) { if (m_FoundHeader) { return(true); } var bodyLength = GetBodyLengthFromHeader(bufferStream, HeaderSize); if (bodyLength < 0) { State = FilterState.Error; return(false); } // no body part if (bodyLength == 0) { m_FoundHeader = true; return(true); } ResetSize(HeaderSize + bodyLength); m_FoundHeader = true; return(false); }
public override Model.PackageInfo ResolvePackage(IBufferStream bufferStream) { byte[] buff = new byte[bufferStream.Length]; int index = 0; foreach (var item in bufferStream.Buffers) { Buffer.BlockCopy(item.Array, item.Offset, buff, index, item.Count); index += item.Count; } int sourcelen = buff.Length - 20; if (sourcelen == 1)//心跳包 { logger.Info($"收到心跳包:\t{SDKClient.Instance.property.CurrentAccount.Session}"); return(new Model.HeartMsgPackage()); } else { var info = RequestInfoParse.instance.ParseRequestInfo(buff, 10, sourcelen); return(info); } // return null; }
public static byte[] Read(this IBufferStream bufferStream) { var buffer = new byte[bufferStream.Length]; bufferStream.Read(buffer, 0, (int)bufferStream.Length); return(buffer); }
public override PipePackageInfo ResolvePackage(IBufferStream bufferStream) { bufferStream.Skip(2); return(new PipePackageInfo { Data = bufferStream.Buffers }); }
public override WpClientPackageInfo ResolvePackage(IBufferStream bufferStream) { //第三个参数用0,1都可以 byte[] header = bufferStream.Buffers.FirstOrDefault().ToArray(); byte[] bodyBuffer = bufferStream.Buffers[1].ToArray(); return(new WpClientPackageInfo(header, bodyBuffer)); }
public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { string source = bufferStream.ReadString((int)bufferStream.Length, Encoding.UTF8); //return new StringPackageInfo(source, BasicStringParser.DefaultInstance); return(new StringPackageInfo(source, StringParser.DefaultInstance)); }
public override HttpPackageInfo ResolvePackage(IBufferStream bufferStream) { var numLen = (int)(bufferStream.Length - m_HeaderSize - 2); bufferStream.Skip(m_HeaderSize); var chunkSize = 0; for (var i = numLen - 1; i >= 0; i--) { chunkSize = chunkSize + (int)bufferStream.ReadByte() * (16 ^ i); } if (chunkSize > 0) { NextReceiveFilter = new HttpChunkDataReceiveFilter(this, m_HeaderSize + numLen + 2 + chunkSize, chunkSize); return(null); } // last chunk var body = m_BodyBuilder.ToString(); m_BodyBuilder = null; return(new HttpPackageInfo("Test", m_HttpHeader, body)); }
public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { var requestInfo = new StringPackageInfo(bufferStream.Skip(1).ReadString((int)bufferStream.Length - 3, Encoding.ASCII), m_Parser); NextReceiveFilter = m_SwitchFilter; return(requestInfo); }
public override MyPackageInfo ResolvePackage(IBufferStream bufferStream) { byte[] header = bufferStream.Buffers[0].ToArray(); //byte[] bodyBuffer = bufferStream.Buffers[1].ToArray(); byte[] allBuffer = bufferStream.Buffers[0].Array.CloneRange(0, (int)bufferStream.Length); return(new MyPackageInfo(allBuffer, allBuffer)); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { byte[] lenbuffer = new byte[length]; bufferStream.Read(lenbuffer, 0, length); int nLen = BitConverter.ToInt16(lenbuffer, 0); return(nLen); }
/// <summary> /// 解析收到的数据 /// </summary> /// <param name="bufferStream"></param> /// <returns></returns> public override MyPackageInfo ResolvePackage(IBufferStream bufferStream) { byte[] header = bufferStream.Buffers[0].ToArray(); byte[] bodyBuffer = bufferStream.Buffers[1].ToArray(); var package = new MyPackageInfo(header, bodyBuffer); return(package); }
public override CustomPackageInfo ResolvePackage(IBufferStream bufferStream) { //第三个参数用0,1都可以 byte[] header = bufferStream.Buffers[0].ToArray(); byte[] bodyBuffer = bufferStream.Buffers[1].ToArray(); //byte[] allBuffer = bufferStream.Buffers[0].Array.CloneRange(0, (int)bufferStream.Length); return(new CustomPackageInfo(header, bodyBuffer)); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { var header = bufferStream.Buffers.FirstOrDefault(); var lenStr = Encoding.ASCII.GetString(header.Array, header.Offset + 4, 8); var len = Int32.Parse(lenStr, System.Globalization.NumberStyles.HexNumber); return(len); }
public override PackageInfo ResolvePackage(IBufferStream bufferStream) { byte[] data = new byte[bufferStream.Length]; bufferStream.Read(data, 0, Convert.ToInt32(bufferStream.Length)); string message = Encoding.ASCII.GetString(data); return(ResolvePackage(data)); }
public override DataPackageInfo ResolvePackage(IBufferStream bufferStream) { var length = Convert.ToInt32(bufferStream.Length); var code = bufferStream.ReadString(length, Encoding.ASCII); var responseInfo = new DataPackageInfo(code); return(responseInfo); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { if (bufferStream.Length <= 4) { return(0); } return((int)bufferStream.Length - 4); }
/// <summary> /// Resolves the package. /// </summary> /// <param name="bufferStream">The received buffer stream.</param> /// <returns></returns> public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { //ignore the first and the last spliter var total = (int)bufferStream.Length; var body = bufferStream.Skip(1).ReadString(total - 2, m_Encoding); var array = body.Split(m_Spliter); return(new StringPackageInfo(array[m_KeyIndex], body, array)); }
public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { long len = bufferStream.Length; string StrRecv = bufferStream.ReadString((int)len, Encoding.ASCII); OnPackageReceived?.Invoke(this, StrRecv); bufferStream.Clear(); return(null); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { ArraySegment <byte> buffers = bufferStream.Buffers[0]; byte[] array = buffers.ToArray(); int len = array[length - 1]; return(len); }