ReadUInt32() public static method

Reads the specified number of bits into an UInt32
public static ReadUInt32 ( byte fromBuffer, int numberOfBits, int readBitOffset ) : uint
fromBuffer byte
numberOfBits int
readBitOffset int
return uint
Exemplo n.º 1
0
        public bool ReadInt32(out Int32 result)
        {
            if (m_bitLength - m_readPosition < 32)
            {
                result = 0;
                return(false);
            }

            result          = (Int32)NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
            m_readPosition += 32;
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads a 64 bit unsigned integer written using Write(UInt64)
        /// </summary>
        public UInt64 ReadUInt64()
        {
            NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);

            ulong low = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);

            m_readPosition += 32;
            ulong high = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);

            ulong retval = low + (high << 32);

            m_readPosition += 32;
            return(retval);
        }
Exemplo n.º 3
0
        public UInt64 PeekUInt64(int numberOfBits)
        {
            NetException.Assert((numberOfBits > 0 && numberOfBits <= 64), "ReadUInt() can only read between 1 and 64 bits");
            NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError);

            ulong retval;

            if (numberOfBits <= 32)
            {
                retval = (ulong)NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
            }
            else
            {
                retval  = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
                retval |= (UInt64)NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition + 32) << 32;
            }
            return(retval);
        }
Exemplo n.º 4
0
        public UInt64 PeekUInt64(int numberOfBits)
        {
            Debug.Assert((numberOfBits > 0 && numberOfBits <= 64), "ReadUInt() can only read between 1 and 64 bits");
            Debug.Assert(m_bitLength - m_readPosition >= numberOfBits, "tried to read past buffer size");

            ulong retval;

            if (numberOfBits <= 32)
            {
                retval = (ulong)NetBitWriter.ReadUInt32(Data, numberOfBits, m_readPosition);
            }
            else
            {
                retval  = NetBitWriter.ReadUInt32(Data, 32, m_readPosition);
                retval |= NetBitWriter.ReadUInt32(Data, numberOfBits - 32, m_readPosition + 32) << 32;
            }
            return(retval);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Decrypt an incoming message encrypted with corresponding Encrypt
        /// </summary>
        /// <param name="msg">message to decrypt</param>
        /// <returns>true if successful; false if failed</returns>
        public override bool Decrypt(NetIncomingMessage msg)
        {
            int numEncryptedBytes = msg.LengthBytes - 4;             // last 4 bytes is true bit length
            int blockSize         = BlockSize;
            int numBlocks         = numEncryptedBytes / blockSize;

            if (numBlocks * blockSize != numEncryptedBytes)
            {
                return(false);
            }

            for (int i = 0; i < numBlocks; i++)
            {
                DecryptBlock(msg.m_data, (i * blockSize), m_tmp);
                Buffer.BlockCopy(m_tmp, 0, msg.m_data, (i * blockSize), m_tmp.Length);
            }

            // read 32 bits of true payload length
            uint realSize = NetBitWriter.ReadUInt32(msg.m_data, 32, (numEncryptedBytes * 8));

            msg.m_bitLength = (int)realSize;
            return(true);
        }
Exemplo n.º 6
0
        public UInt32 PeekUInt32()
        {
            uint retval = NetBitWriter.ReadUInt32(Data, 32, m_readPosition);

            return(retval);
        }