Пример #1
0
        /// <summary>
        /// Checks the CRC of the incomming packet
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        private static bool CheckCRC(byte[] buffer, int offset, int count)
        {
            uint packetCrc = BitConverter.ToUInt32(buffer, offset + 8);

            for (int i = offset + 8; i < offset + 12; i++)
            {
                buffer[i] = 0;
            }

            uint crc = CRC32c.GetCRC(buffer, offset, count);

            return(packetCrc == crc);
        }
Пример #2
0
        /// <summary>
        /// Updates the packets CRC.
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        private void UpdateCRC(byte[] buffer, int offset, int count)
        {
            uint crc = CRC32c.GetCRC(buffer, offset, count);

            Buffer.BlockCopy(BitConverter.GetBytes(crc), 0, buffer, offset + 8, 4);
        }