Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
        {
            if ((int)valueLength < 0 || (int)valueLength % 8 != 0)
            {
                return((Option)null);
            }
            int length = (int)valueLength / 8;

            TcpOptionSelectiveAcknowledgmentBlock[] acknowledgmentBlockArray = new TcpOptionSelectiveAcknowledgmentBlock[length];
            for (int index = 0; index != length; ++index)
            {
                acknowledgmentBlockArray[index] = new TcpOptionSelectiveAcknowledgmentBlock(ByteArrayExtensions.ReadUInt(buffer, ref offset, Endianity.Big), ByteArrayExtensions.ReadUInt(buffer, ref offset, Endianity.Big));
            }
            return((Option) new TcpOptionSelectiveAcknowledgment((IList <TcpOptionSelectiveAcknowledgmentBlock>)acknowledgmentBlockArray));
        }
Beispiel #2
0
        /// <summary>
        /// Tries to read the option from a buffer starting from the option value (after the type and length).
        /// </summary>
        /// <param name="buffer">The buffer to read the option from.</param>
        /// <param name="offset">The offset to the first byte to read the buffer. Will be incremented by the number of bytes read.</param>
        /// <param name="valueLength">The number of bytes the option value should take according to the length field that was already read.</param>
        /// <returns>On success - the complex option read. On failure - null.</returns>
        Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
        {
            if (valueLength < OptionValueMinimumLength || valueLength % TcpOptionSelectiveAcknowledgmentBlock.SizeOf != 0)
            {
                return(null);
            }

            int numBlocks = valueLength / TcpOptionSelectiveAcknowledgmentBlock.SizeOf;

            TcpOptionSelectiveAcknowledgmentBlock[] blocks = new TcpOptionSelectiveAcknowledgmentBlock[numBlocks];
            for (int i = 0; i != numBlocks; ++i)
            {
                blocks[i] = new TcpOptionSelectiveAcknowledgmentBlock(buffer.ReadUInt(ref offset, Endianity.Big),
                                                                      buffer.ReadUInt(ref offset, Endianity.Big));
            }

            return(new TcpOptionSelectiveAcknowledgment(blocks));
        }