public bool IsValid(Span <byte> data, int checksumTagStartIndex)
        {
            if (checksumTagStartIndex < 0 || (checksumTagStartIndex + ChecksumLength) != data.Length)
            {
                return(false);
            }

            int sum = 0;

            for (int i = 0; i < checksumTagStartIndex; i++)
            {
                sum += data[i];
            }

            int         expectedChecksum = sum % Modulus;
            Span <byte> expectedDigits   = stackalloc byte[ChecksumValueLength];

            _converter.Convert(number: expectedChecksum, into: expectedDigits, count: ChecksumValueLength);

            var receivedChecksum = data.Slice(checksumTagStartIndex + 3, ChecksumValueLength);

            return(receivedChecksum.SequenceEqual(expectedDigits));
        }
Ejemplo n.º 2
0
        public bool IsValid(ReadOnlySpan <byte> data, FixMessageContext msgContext)
        {
            var endingTagPos = msgContext.ChecksumTagStartIndex;

            if (endingTagPos < 0 || (endingTagPos + KnownFixTags.Checksum.Length + ChecksumLength + 1) != data.Length)
            {
                return(false);
            }

            Span <byte> expectedDigits = stackalloc byte[ChecksumLength];

            _converter.Convert(number: msgContext.ChecksumValue, into: expectedDigits, count: ChecksumLength);

            var receivedChecksum = data.Slice(endingTagPos + KnownFixTags.Checksum.Length, ChecksumLength);

            return(receivedChecksum.SequenceEqual(expectedDigits));
        }
Ejemplo n.º 3
0
        public bool IsValid(ReadOnlySpan <byte> data, FixMessageContext msgContext)
        {
            var endingTagPos   = msgContext.ChecksumTagStartIndex;
            int startingTagPos = msgContext.MessageTypeTagStartIndex;
            int expectedLength = endingTagPos - startingTagPos;

            if (expectedLength <= 0)
            {
                return(false);
            }
            int         digitsCount    = (int)(Math.Log10(expectedLength) + 1);
            Span <byte> expectedDigits = stackalloc byte[digitsCount + 1];

            _converter.Convert(number: expectedLength, into: expectedDigits, count: digitsCount);
            expectedDigits[digitsCount] = Constants.SOHByte;

            int lengthTagPos    = msgContext.LengthTagStartIndex;
            var fromLengthStart = data.Slice(lengthTagPos + KnownFixTags.Length.Length);

            return(fromLengthStart.StartsWith(expectedDigits));
        }