public static byte[] Compute(byte[] bytes) { var hasher = new Crc32Hasher(); var hash = hasher.ComputeHash(bytes); return(hash); }
public void ParseFromValid() { Crc32Hasher crc32 = new Crc32Hasher(); string payload = "kafka"; byte magic = 1; byte attributes = 0; byte[] payloadData = Encoding.UTF8.GetBytes(payload); byte[] payloadSize = BitConverter.GetBytes(payloadData.Length); byte[] checksum = crc32.ComputeHash(payloadData); byte[] messageData = new byte[payloadData.Length + 2 + payloadSize.Length + checksum.Length]; Buffer.BlockCopy(payloadSize, 0, messageData, 0, payloadSize.Length); messageData[4] = magic; messageData[5] = attributes; Buffer.BlockCopy(checksum, 0, messageData, payloadSize.Length + 2, checksum.Length); Buffer.BlockCopy(payloadData, 0, messageData, payloadSize.Length + 2 + checksum.Length, payloadData.Length); Message message = Message.ParseFrom(messageData); Assert.IsNotNull(message); Assert.AreEqual(magic, message.Magic); Assert.IsTrue(payloadData.SequenceEqual(message.Payload)); Assert.IsTrue(checksum.SequenceEqual(message.Checksum)); }
public static byte[] Compute(byte[] bytes) { var hasher = new Crc32Hasher(); byte[] hash = hasher.ComputeHash(bytes); return hash; }
internal static uint ComputeCrcUint32(byte[] bytes, int offset, int count) { var hasher = new Crc32Hasher(); return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, bytes, offset, count); }
internal static uint ComputeCrcUint32(byte[] bytes, int offset, int count) { var hasher = new Crc32Hasher(); return(~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, bytes, offset, count)); }