当前位置: 首页>>代码示例>>C#>>正文


C# Crc32.Calculate方法代码示例

本文整理汇总了C#中Crc32.Calculate方法的典型用法代码示例。如果您正苦于以下问题:C# Crc32.Calculate方法的具体用法?C# Crc32.Calculate怎么用?C# Crc32.Calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crc32的用法示例。


在下文中一共展示了Crc32.Calculate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildId3V3Tag

        private static byte[] BuildId3V3Tag(TagContainer tagContainer)
        {
            byte[] tagBytes;
            var tag = tagContainer.GetId3V23Descriptor();
            var frameBytes = GetFrameBytes(tagContainer);

            //
            //  Calculate the CRC32 value of the frameBytes ( before unsync!)
            //
            if (tag.CrcDataPresent)
            {
                var crc32 = new Crc32(Crc32.DefaultPolynom);
                var crcValue = crc32.Calculate(frameBytes);

                tag.SetCrc32(crcValue);
            }

            //
            //  OK. Build the complete tag
            //
            var extendedHeaderBytes = GetExtendedHeaderV3(tagContainer);
            var tagHeader = GetTagHeader(tagContainer);
            var rawTagBytes = BuildFinalTag(tagHeader, extendedHeaderBytes, frameBytes, tag.PaddingSize, false);
            if (tag.Unsynchronisation)
            {
                tagBytes = AddUnsyncBytes(rawTagBytes);
            }
            else
            {
                tagBytes = rawTagBytes;
            }

            return tagBytes;
        }
开发者ID:saitodisse,项目名称:id3tag.net,代码行数:34,代码来源:IOController.cs

示例2: Write

        public void Write(TagContainer tagContainer, Stream input, Stream output)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (tagContainer == null)
            {
                throw new ArgumentNullException("tagContainer");
            }

            //
            //  Validate whether the tag container is in ID3V2.3 formaz
            //
            string message;
            var isTagValid = ValidateTag(tagContainer, out message);
            if (!isTagValid)
            {
                throw new InvalidID3StructureException(message);
            }

            //
            //  OK. ID3Tag is valid. Let's write the tag.
            //
            //  Calculate the CRC32 value of the frameBytes ( before unsync!)
            //
            byte[] extendedHeaderBytes;
            var tagHeader = GetTagHeader(tagContainer);
            var frameBytes = GetFrameBytes(tagContainer);

            if (tagContainer.Tag.CrcDataPresent)
            {
                var crc32 = new Crc32(Crc32.DefaultPolynom);
                var crcValue = crc32.Calculate(frameBytes);

                tagContainer.Tag.SetCrc32(crcValue);
            }

            //
            //  OK. Build the complete tag
            //
            byte[] tagBytes;
            var extendedHeaderLength = GetExtendedHeaderLength(tagContainer, out extendedHeaderBytes);
            var rawTagBytes = BuildTag(tagHeader, extendedHeaderBytes, frameBytes, tagContainer.Tag.PaddingSize);
            if (tagContainer.Tag.Unsynchronisation)
            {
                tagBytes = AddUnsyncBytes(rawTagBytes);
            }
            else
            {
                tagBytes = rawTagBytes;
            }

            //
            //  encode the length
            //
            var length = tagBytes.LongLength -10;
            //if (tagContainer.Tag.ExtendedHeader)
            //{
            //    // Header + Size Coding.
            //    length += extendedHeaderLength + 4;
            //}

            var bits = GetBitCoding(length);
            var lengthBytes = new byte[4];

            EncodeLength(bits, lengthBytes);
            Array.Copy(lengthBytes, 0, tagBytes, 6, 4);

            //
            //  Build the tag bytes and start writing.
            //
            if (!input.CanRead)
            {
                throw new ID3IOException("Cannot read input stream");
            }
            if (!output.CanWrite)
            {
                throw new ID3IOException("Cannot write to output stream");
            }

            WriteToStream(input, output, tagBytes);
        }
开发者ID:saitodisse,项目名称:id3tag.net,代码行数:87,代码来源:IOController.cs


注:本文中的Crc32.Calculate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。