Custom Filter with FixedHeader

Mar 25, 2014 at 8: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.
Coordinator
Mar 25, 2014 at 8:31 AM
Why don't you use FixedSizeReceiveFilter? It is more suitable for your protocol, because you have the length in the request header:
http://docs.supersocket.net/v1-6/en-US/The-Built-in-Common-Format-Protocol-Implementation-Templates
Mar 25, 2014 at 8:46 AM
Edited Mar 25, 2014 at 8: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);
            Log.Debug(BitConverter.ToString(bodyBuffer));

            return new BinaryRequestInfo(commandKey, bodyBuffer.CloneRange(offset, length));
        }
Coordinator
Mar 25, 2014 at 8: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.