protected override StringRequestInfo ProcessMatchedRequest(byte[] readBuffer, int offset, int length) { var requestInfo = m_Parser.ParseRequestInfo(Encoding.ASCII.GetString(readBuffer, offset + 1, length - 3)); NextReceiveFilter = m_SwitchFilter; return(requestInfo); }
protected override StringRequestInfo ProcessMatchedRequest(byte[] readBuffer, int offset, int length) { //TODO LIST: decode the readBuffer byte[] src = CodeUtils.adDecode(readBuffer.CloneRange(offset, length - 2)); String data = BitConverter.ToString(src, 0, src.Length).Replace("-", ""); //TODO: construct the receving adler data //String data = Encoding.ASCII.GetString(src, 0, src.Length); //preamble(1B) version(1B) leng(2B) deviceId(4B) Pdutype(1B) seq(1B) oid-list/tag-list(N) crc(2B) String preamble = data.Substring(0, 2); String version = data.Substring(2, 2); String leng = data.Substring(4, 4); String deviceId = data.Substring(8, 8); String pduType = data.Substring(16, 2); String seq = data.Substring(18, 2); String settings = data.Substring(20, data.Length - 4 - 12 * 2); //减去结尾回车换行符号,减去总的字节数 String crcs = data.Substring(data.Length - 8, 4); String result = "Adler:" + preamble + "," + version + "," + leng + "," + deviceId + "," + pduType + "," + seq + "," + settings + "," + crcs; BasicRequestInfoParser m_Parser = new BasicRequestInfoParser(":", ","); return(m_Parser.ParseRequestInfo(result)); }
protected override StringRequestInfo ResolveRequestInfo(ArraySegment <byte> header, byte[] bodyBuffer, int offset, int length) { byte[] tmpHead = header.Array; byte[] tmpBody = bodyBuffer.CloneRange(offset, length); byte[] src = new byte[tmpHead.Length + tmpBody.Length]; tmpHead.CopyTo(src, 0); tmpBody.CopyTo(src, tmpHead.Length); String data = BitConverter.ToString(src, 0, src.Length).Replace("-", ""); //TODO: construct the receving casic data String preamble = data.Substring(0, 2); String version = data.Substring(2, 2); String leng = data.Substring(4, 4); String deviceId = data.Substring(8, 12); String routeFlag = data.Substring(20, 2); String dstNodeAddr = data.Substring(22, 4); String pduType = data.Substring(26, 4); String seq = data.Substring(30, 2); String settings = data.Substring(32, data.Length - 18 * 2); String crcs = data.Substring(data.Length - 4, 4); String result = "Casic:" + preamble + "," + version + "," + leng + "," + deviceId + "," + routeFlag + "," + dstNodeAddr + "," + pduType + "," + seq + "," + settings + "," + crcs; BasicRequestInfoParser m_Parser = new BasicRequestInfoParser(":", ","); return(m_Parser.ParseRequestInfo(result)); // return new BinaryRequestInfo(Encoding.UTF8.GetString(header.Array, header.Offset, 4), bodyBuffer.CloneRange(offset, length)); }
/* * public SZLiquidCmdFilter() * : base(m_Terminator, m_Encoding, m_Parser) * { * * } * */ protected override StringRequestInfo ProcessMatchedRequest(byte[] readBuffer, int offset, int length) { byte[] head = new byte[9]; Buffer.BlockCopy(readBuffer, offset, head, 0, 9); var requestInfo = m_Parser.ParseRequestInfo(Encoding.ASCII.GetString(readBuffer, offset + 9, length - 9 - 2) + ',' + BitConverter.ToString(head).Replace("-", "")); // var requestInfo = m_Parser.ParseRequestInfo(Encoding.ASCII.GetString(readBuffer, offset + 9, length - 9)); return(requestInfo); }
protected override StringRequestInfo ProcessMatchedRequest(byte[] readBuffer, int offset, int length) { if (length < 20) { Console.WriteLine("Ignore request"); return(NullRequestInfo); } var line = Encoding.ASCII.GetString(readBuffer, offset, length); return(m_Parser.ParseRequestInfo(line.Substring(2, line.Length - 4))); }
protected override StringRequestInfo ProcessMatchedRequest(byte[] buffer, int offset, int length, bool toBeCopied) { return(m_Parser.ParseRequestInfo(Encoding.ASCII.GetString(buffer, offset, length))); }