ReadByte() public static method

Read 1-8 bits from a buffer into a byte
public static ReadByte ( byte fromBuffer, int numberOfBits, int readBitOffset ) : byte
fromBuffer byte
numberOfBits int
readBitOffset int
return byte
        //
        // 1 bit
        //
        /// <summary>
        /// Reads a 1-bit Boolean without advancing the read pointer
        /// </summary>
        public bool PeekBoolean()
        {
            NetException.Assert(m_bitLength - m_readPosition >= 1, c_readOverflowError);
            var retval = NetBitWriter.ReadByte(m_data, 1, m_readPosition);

            return(retval > 0);
        }
        public sbyte PeekSByte()
        {
            NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
            byte retval = NetBitWriter.ReadByte(m_data, 8, m_readPosition);

            return((sbyte)retval);
        }
        public byte ReadByte(int numberOfBits)
        {
            byte retval = NetBitWriter.ReadByte(m_data, numberOfBits, m_readPosition);

            m_readPosition += numberOfBits;
            return(retval);
        }
Beispiel #4
0
        /// <summary>
        /// Reads 1 to 8 bits into a byte
        /// </summary>
        public byte ReadByte(int numberOfBits)
        {
            NetException.Assert(numberOfBits > 0 && numberOfBits <= 8, "ReadByte(bits) can only read between 1 and 8 bits");
            byte retval = NetBitWriter.ReadByte(m_data, numberOfBits, m_readPosition);

            m_readPosition += numberOfBits;
            return(retval);
        }
Beispiel #5
0
        /// <summary>
        /// Reads a boolean value (stored as a single bit) written using Write(bool)
        /// </summary>
        public bool ReadBoolean()
        {
            NetException.Assert(m_bitLength - m_readPosition >= 1, c_readOverflowError);
            byte retval = NetBitWriter.ReadByte(m_data, 1, m_readPosition);

            m_readPosition += 1;
            return(retval > 0 ? true : false);
        }
        /// <summary>
        /// Reads 1 to 8 bits into a byte
        /// </summary>
        public byte ReadByte(int numberOfBits)
        {
            NetException.Assert(numberOfBits > 0 && numberOfBits < 8);
            byte retval = NetBitWriter.ReadByte(m_data, numberOfBits, m_readPosition);

            m_readPosition += numberOfBits;
            return(retval);
        }
        public sbyte ReadSByte()
        {
            Debug.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
            byte retval = NetBitWriter.ReadByte(Data, 8, m_readPosition);

            m_readPosition += 8;
            return((sbyte)retval);
        }
Beispiel #8
0
        /// <summary>
        /// Reads a 1-bit <see cref="bool"/> without advancing the read position.
        /// </summary>
        public static bool PeekBool(this IBitBuffer buffer)
        {
            if (!buffer.HasEnoughBits(1))
            {
                throw new EndOfMessageException();
            }

            return(NetBitWriter.ReadByte(buffer.GetBuffer(), buffer.BitPosition, 1) > 0);
        }
Beispiel #9
0
        /// <summary>
        /// Reads the specified number of bits into a <see cref="byte"/> without advancing the read position.
        /// </summary>
        public static byte PeekByte(this IBitBuffer buffer, int bitCount)
        {
            if (!buffer.HasEnoughBits(bitCount))
            {
                throw new EndOfMessageException();
            }

            return(NetBitWriter.ReadByte(buffer.GetBuffer(), buffer.BitPosition, bitCount));
        }
Beispiel #10
0
        public static sbyte PeekSByte(this IBitBuffer buffer)
        {
            if (!buffer.HasEnoughBits(8))
            {
                throw new EndOfMessageException();
            }

            return((sbyte)NetBitWriter.ReadByte(buffer.GetBuffer(), buffer.BitPosition, 8));
        }
Beispiel #11
0
 /// <summary>
 /// Reads a byte and returns true or false for success
 /// </summary>
 public bool ReadByte(out byte result)
 {
     if (m_bitLength - m_readPosition < 8)
     {
         result = 0;
         return(false);
     }
     result          = NetBitWriter.ReadByte(m_data, 8, m_readPosition);
     m_readPosition += 8;
     return(true);
 }
Beispiel #12
0
        /// <summary>
        /// Reads 1 to 8 bits into a <see cref="byte"/>.
        /// </summary>
        public static bool ReadByte(this IBitBuffer buffer, int bitCount, out byte result)
        {
            if (!buffer.HasEnoughBits(bitCount))
            {
                result = default;
                return(false);
            }

            result              = NetBitWriter.ReadByte(buffer.GetBuffer(), buffer.BitPosition, bitCount);
            buffer.BitPosition += bitCount;
            return(true);
        }
        public byte PeekByte(int numberOfBits)
        {
            byte retval = NetBitWriter.ReadByte(Data, numberOfBits, m_readPosition);

            return(retval);
        }
        //
        // 8 bit
        //
        public byte PeekByte()
        {
            byte retval = NetBitWriter.ReadByte(Data, 8, m_readPosition);

            return(retval);
        }
        //
        // 1 bit
        //
        public bool PeekBoolean()
        {
            byte retval = NetBitWriter.ReadByte(Data, 1, m_readPosition);

            return(retval > 0 ? true : false);
        }