Example #1
0
        public byte ReadByte()
        {
            NetUtility.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
            int  bytePtr = m_readPosition >> 3;
            byte retval  = Data[bytePtr];

            m_readPosition += 8;
            return(retval);
        }
Example #2
0
        //
        // 64 bit
        //
        //[CLSCompliant(false)]
        public UInt64 ReadUInt64()
        {
            NetUtility.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
            ulong low    = ReadUInt32();
            ulong high   = ReadUInt32();
            ulong retval = low + (high << 32);

            return(retval);
        }
Example #3
0
        //
        // 8 bit
        //
        public bool ReadBoolean()
        {
            NetUtility.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
            int  bytePtr = m_readPosition >> 3;
            byte retval  = Data[bytePtr];

            m_readPosition += 8;
            return(retval > 0 ? true : false);
        }
Example #4
0
 public Int64 ReadInt64()
 {
     NetUtility.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
     unchecked
     {
         ulong retval     = ReadUInt64();
         long  longRetval = (long)retval;
         return(longRetval);
     }
 }
Example #5
0
        //[CLSCompliant(false)]
        public UInt16 ReadUInt16()
        {
            NetUtility.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
            int bytePtr = m_readPosition >> 3;

            ushort retval = Data[bytePtr++];

            retval |= (ushort)(Data[bytePtr] << 8);

            m_readPosition += 16;
            return(retval);
        }
Example #6
0
        public void ReadBytes(byte[] into, int offset, int numberOfBytes)
        {
            NetUtility.Assert(m_bitLength - m_readPosition >= (numberOfBytes * 8), c_readOverflowError);
            Debug.Assert(offset + numberOfBytes <= into.Length);

            int bytePtr = m_readPosition >> 3;

            for (int i = 0; i < numberOfBytes; i++)
            {
                into[offset++] = Data[bytePtr++];
            }
            m_readPosition += (numberOfBytes * 8);
        }
Example #7
0
        //[CLSCompliant(false)]
        public UInt32 ReadUInt32()
        {
            NetUtility.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
            int bytePtr = m_readPosition >> 3;

            UInt32 retval = Data[bytePtr++];

            retval |= (UInt32)(Data[bytePtr++] << 8);
            retval |= (UInt32)(Data[bytePtr++] << 16);
            retval |= (UInt32)(Data[bytePtr] << 24);

            m_readPosition += 32;
            return(retval);
        }
Example #8
0
        //[CLSCompliant(false)]
        public UInt64 ReadUInt64(int numberOfBits)
        {
            NetUtility.Assert(m_bitLength - m_readPosition >= (((numberOfBits + 7) >> 3) * 8), c_readOverflowError);

            ulong result  = 0;
            int   bytePtr = m_readPosition / 8;

            for (int bits = 0; bits < numberOfBits; bits += 8)
            {
                result |= ((ulong)Data[bytePtr++]) << bits;
            }

            m_readPosition += ((numberOfBits + 7) / 8) * 8;
            return(result);
        }
Example #9
0
        /// <summary>
        /// Reads a string
        /// </summary>
        public string ReadString()
        {
            int byteLen = (int)ReadVariableUInt32();

            if (byteLen == 0)
            {
                return(String.Empty);
            }

            NetUtility.Assert(m_bitLength - m_readPosition >= (byteLen * 8), c_readOverflowError);

            if ((m_readPosition & 7) == 0)
            {
                // read directly
                string retval = System.Text.Encoding.UTF8.GetString(Data, m_readPosition >> 3, byteLen);
                m_readPosition += (8 * byteLen);
                return(retval);
            }

            byte[] bytes = ReadBytes(byteLen);
            return(System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length));
        }