Esempio n. 1
0
        public int CalculateCrc()
        {
            if (!IsValid)
            {
                return(0);
            }

            using (MemoryStream stream = new MemoryStream())
            {
                // serialise tags to a buffer, without any padding
                FrameManager.Serialize(this, stream);

                // obtain whole buffer as byte array
                byte[] buffer = stream.ToArray();

                // calculate the size of the tag without the padding
                int tagsize = (int)buffer.Length - (int)Header.PaddingSize;

                // create and calculate crc-32 for the tag
                ICSharpCode.SharpZipLib.Checksums.Crc32 crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();
                crc.Update(buffer, 0, tagsize);
                return((int)crc.Value);
            }
        }