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 BufferedPackageInfo ResolvePackage(IBufferStream bufferStream) { var key = bufferStream.ReadString(4, Encoding.UTF8); bufferStream.Skip(2); return(new BufferedPackageInfo(key, bufferStream.Take((int)bufferStream.Length - 6))); }
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 PipePackageInfo ResolvePackage(IBufferStream bufferStream) { bufferStream.Skip(2); return(new PipePackageInfo { Data = bufferStream.Buffers }); }
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)); }
/// <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)); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { bufferStream.Skip(FixedHeaderTryConst.KEYSIZE); byte[] bodySizeBuf = new byte[FixedHeaderTryConst.BODYSIZE_LEN]; //注意 Read方法的第二个参数,目标数组的偏移 bufferStream.Read(bodySizeBuf, 0, FixedHeaderTryConst.BODYSIZE_LEN); return(PackageBodyOperator.GetBodyLen(bodySizeBuf)); //throw new NotImplementedException(); }
public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { var total = (int)bufferStream.Length; var key = bufferStream.ReadString(4, Encoding.ASCII); bufferStream.Skip(4); // skip length part var body = bufferStream.ReadString(total - HeaderSize, Encoding.ASCII); return(new StringPackageInfo(key, body, new string[] { body })); }
public override FPackageInfo ResolvePackage(IBufferStream bufferStream) { var PackageTogalSize = (int)(bufferStream.Length); bufferStream.Skip(H_SIZE); byte[] data = new byte[PackageTogalSize - H_SIZE]; bufferStream.Read(data, 0, PackageTogalSize - H_SIZE); return(new FPackageInfo(data)); }
public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { var length = bufferStream.Length; if (length < 20) { Console.WriteLine("Ignore request"); return(null); } return(new StringPackageInfo(bufferStream.Skip(2).ReadString((int)length - 4, Encoding.ASCII), m_Parser)); }
public override PackageInfo <string, byte[]> ResolvePackage(IBufferStream bufferStream) { string key = bufferStream.ReadString(4, Encoding.UTF8); if (bufferStream.Length > 4) { byte[] body = new byte[bufferStream.Length - 4]; bufferStream.Skip(4).Read(body, 4, body.Length); return(new PackageInfo <string, byte[]>(key, body)); } return(new PackageInfo <string, byte[]>(key, null)); }
public override ReceieveMessage ResolvePackage(IBufferStream bs) { ReceieveMessage res = new ReceieveMessage(); //var h = new byte[64]; //bs.Read(h, 0, 64); //var mmm = Encoding.UTF8.GetString(h); bs.Skip(64); var bodyBytes = new byte[bodyLength]; bs.Read(bodyBytes, 0, bodyLength); res.Length = bodyLength; res.DataStr = Encoding.UTF8.GetString(bodyBytes); res.ReceiveDataType = GetReceiveType(res.DataStr); return(res); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { var strLen = bufferStream.Skip(4).ReadString(4, Encoding.ASCII); return(int.Parse(strLen.TrimStart('0'))); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { bufferStream.Skip(4); return(bufferStream.ReadUInt16()); }
public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { return(new StringPackageInfo(string.Empty, bufferStream.Skip(1).ReadString((int)bufferStream.Length - 2, Encoding.UTF8), null)); }
public override HttpPackageInfo ResolvePackage(IBufferStream bufferStream) { m_ParentFilter.m_BodyBuilder.Append(bufferStream.Skip(m_Size - m_ChunkSize).ReadString(this.m_ChunkSize, Encoding.UTF8)); NextReceiveFilter = m_ParentFilter; return(null); }
public override BufferedPackageInfo ResolvePackage(IBufferStream bufferStream) { return(new BufferedPackageInfo(bufferStream.Skip(15).ReadByte().ToString("X"), bufferStream.Buffers)); }
private int GetPayloadLength(IBufferStream bufferStream, int length) { if (length == 2) { var flag = bufferStream.ReadByte(); m_Final = (FINAL_FLAG & flag) == flag; m_OpCode = (sbyte)(flag & 0x08); // one byte playload length var playloadLen = (int)bufferStream.ReadByte(); //the highest bit is mask indicator m_Masked = playloadLen > 128; // remove the mask byte playloadLen = playloadLen % 128; // no extend playload length if (playloadLen < 126) { if (!m_Masked) { return(playloadLen); } // masking-key: 4 bytes return(playloadLen + 4); } // playload length takes 2 bytes if (playloadLen == 126) { ResetSize(4); return(-1); } else// playload length takes 8 bytes { ResetSize(10); return(-1); } } else if (length == 4) { bufferStream.Skip(2); // 2 bytes var playloadLen = bufferStream.ReadUInt16(); if (m_Masked) // add mask key's length { playloadLen += 4; } return(playloadLen); } else // length = 8 { bufferStream.Skip(2); // 8 bytes var playloadLen = bufferStream.ReadUInt64(); if (m_Masked) // add mask key's length { playloadLen += 4; } return((int)playloadLen); } }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { return(bufferStream.Skip(length - 1).ReadByte()); }
public override HttpPackageInfo ResolvePackage(IBufferStream bufferStream) { var total = (int)bufferStream.Length; return(new HttpPackageInfo("Test", m_HttpHeader, bufferStream.Skip(m_HeaderSize).ReadString(total - m_HeaderSize, Encoding.UTF8))); }