public void TryParseFrame_ShouldReturnTrue_OnTwoCompleteMessage()
        {
            var firstFrame    = _createMessage(150);
            var secondFrame   = _createMessage(160);
            var firstSegment  = new SequenceSegment(firstFrame);
            var secondSegment = firstSegment.Add(secondFrame);

            var fullFrame = new ReadOnlySequence <byte>(
                firstSegment, 0,
                secondSegment, 8);

            Assert.True(_frameParser.TryParseFrame(ref fullFrame, out var firstMessage));
            Assert.True(_frameParser.TryParseFrame(ref fullFrame, out var secondMessage));
        }
예제 #2
0
        public void TryRead_ShouldReturnTrue_OnSegmentSplitted()
        {
            var buffer        = _createBuffer();
            var firstSegment  = new SequenceSegment(buffer.Slice(0, 4));
            var secondSegment = firstSegment.Add(buffer.Slice(4, 4));

            var input = new ReadOnlySequence <byte>(
                firstSegment, 0,
                secondSegment, 4);

            var reader = new SequenceReader(input);

            reader.TryRead(BinaryPrimitives.ReadInt32LittleEndian, out var firstValue);
            reader.TryRead(BinaryPrimitives.ReadInt32LittleEndian, out var secondValue);

            Assert.Equal(_firstValue, firstValue);
            Assert.Equal(_secondValue, secondValue);
        }