GSF.Communication.Radius.RadiusPacket.ParseBinaryImage C# (CSharp) Method

ParseBinaryImage() public method

Parses RadiusPacket object by parsing the specified buffer containing a binary image.
is null.
public ParseBinaryImage ( byte buffer, int startIndex, int length ) : int
buffer byte Buffer containing binary image to parse.
startIndex int 0-based starting index in the to start parsing.
length int Valid number of bytes within from .
return int
        public int ParseBinaryImage(byte[] buffer, int startIndex, int length)
        {
            if ((object)buffer == null)
                throw new ArgumentNullException(nameof(buffer));

            int imageLength = BinaryLength;

            if (length >= imageLength)
            {
                // Binary image has sufficient data.
                UInt16 size;
                m_type = (PacketType)(buffer[startIndex]);
                m_identifier = buffer[startIndex + 1];
                size = EndianOrder.ToUInt16(buffer, startIndex + 2);
                Buffer.BlockCopy(buffer, startIndex + 4, m_authenticator, 0, m_authenticator.Length);

                // Parse all attributes in the packet.
                int cursor = 20;

                while (cursor < size)
                {
                    RadiusPacketAttribute attribute = new RadiusPacketAttribute(buffer, startIndex + cursor, length);
                    m_attributes.Add(attribute);
                    cursor += attribute.BinaryLength;
                }

                return imageLength;
            }

            // Binary image does not have sufficient data.
            return 0;
        }