Esempio n. 1
0
        public void Calculate_GivenSequenceWithSingleSegment_ShouldReturnExpectedChecksum()
        {
            //Arrange
            var segment  = new byte[] { 0x10, 0x01, 0x18, 0xc9, 0xf8, 0x86, 0x94, 0xeb, 0x2c };
            var sequence = new SequenceBuilder <byte>().Append(segment).Build();

            //Act
            var actual = Crc32C.Calculate(sequence);

            //Assert
            const uint expected = 2355953212;

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
        public void Calculate_GivenSequenceWithMultipleSegments_ShouldReturnExpectedChecksum()
        {
            //Arrange
            var s1       = new byte[] { 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x6c, 0x6f, 0x6e, 0x65, 0x2d, 0x33, 0x30, 0x2d, 0x35, 0x10, 0x00, 0x18, 0xc7, 0xee, 0xa3, 0x93, 0xeb, 0x2c, 0x58, 0x01 };
            var s2       = new byte[] { 0x10, 0x01, 0x18, 0xc9, 0xf8, 0x86, 0x94, 0xeb, 0x2c };
            var sequence = new SequenceBuilder <byte>().Append(s1).Append(s2).Build();

            //Act
            var actual = Crc32C.Calculate(sequence);

            //Assert
            const uint expected = 1079987866;

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
 private static bool HasValidCheckSum(ReadOnlySequence <byte> input)
 => input.ReadUInt32(Constants.MagicNumber.Length, true) == Crc32C.Calculate(input.Slice(Constants.MetadataSizeOffset));