Incog.Messaging.IncogStream.ReadUInt16 C# (CSharp) Method

ReadUInt16() private method

Read a 2-byte unsigned integer, unencrypted, from the stream. If either the first or second byte is missing (-1), then 0 is returned.
private ReadUInt16 ( ) : ushort
return ushort
        private ushort ReadUInt16()
        {
            // Get the first byte, which contains the length, and boundary check
            int firstByte = this.innerStream.ReadByte();
            if (firstByte == -1) return 0;

            // Get the second byte, which contains the length, and boundary check
            int secondByte = this.innerStream.ReadByte();
            if (secondByte == -1) return 0;

            // Convert the bytes to the 16-bit unsigned integer
            ushort result = (ushort)firstByte;
            result += (ushort)(secondByte * 256);
            return result;
        }