Exemple #1
0
        internal static void Write(ref byte[] buf, ref int bitPos, bool val)
        {
#if DEBUG
            int resetPos = bitPos;
#endif

            EnsureBufferSize(ref buf, bitPos + 1);

            int  bytePos   = bitPos / 8;
            int  bitOffset = bitPos % 8;
            byte bitFlag   = (byte)(1 << bitOffset);
            byte bitMask   = (byte)((~bitFlag) & 0xff);
            buf[bytePos] &= bitMask;
            if (val)
            {
                buf[bytePos] |= bitFlag;
            }
            bitPos++;

#if DEBUG
            bool testVal = MsgReader.ReadBoolean(buf, ref resetPos);
            if (testVal != val || resetPos != bitPos)
            {
                DebugConsole.ThrowError("Boolean written incorrectly! " + testVal + ", " + val + "; " + resetPos + ", " + bitPos);
            }
#endif
        }
Exemple #2
0
 public bool ReadBoolean()
 {
     return(MsgReader.ReadBoolean(buf, ref seekPos));
 }