Custom Filter with FixedHeader

Mar 25, 2014 at 9:08 AM
How can I use fixed header filter in following data format

Header-Key-Length-DATA BODY-CRC-Tail
Header = "##"
Tail = 0x0d

I was trying custom filter with RequestFilterBase ; If body contains 0x0d ,then filtering terminates there and causes parsing error when data processing ; Is there any good example for this scenario.
Mar 25, 2014 at 9:31 AM
Why don't you use FixedSizeReceiveFilter? It is more suitable for your protocol, because you have the length in the request header:
Mar 25, 2014 at 9:46 AM
Edited Mar 25, 2014 at 9:47 AM
Thanks for quick reply ,I am trying fixedSizeRecieveFilter now

Still having some errors ; the request received at ExecuteCommand contains header or some extra data for next command

My data may not be complete or may contain more than one message,Does FixedSizeRecieveFilter handle this.
protected override int GetBodyLengthFromHeader(byte[] header, int offset, int length)
            var msgLength = Convert.ToInt32(BitConverter.ToString(header, 3, 2).Replace("-", ""), 16);
            Log.Debug("Length:" + msgLength + " Head: " + BitConverter.ToString(header));
            return msgLength;
protected override BinaryRequestInfo ResolveRequestInfo(ArraySegment<byte> header, byte[] bodyBuffer, int offset, int length)
            string commandKey = "";
            byte[] head = new byte[] { header.Array[2] };
            commandKey = BitConverter.ToString(head);

            return new BinaryRequestInfo(commandKey, bodyBuffer.CloneRange(offset, length));
Mar 25, 2014 at 9:58 AM
Package format: [Header][Body]

In the constructor, you should pass in the length of the header. And in the method GetBodyLengthFromHeader, you should return the length of the other part then header.