本文整理汇总了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;
}
示例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);
}