public void ValidInputOnlyMultiByte() { Span <byte> inputSpan = new byte[1000]; Base64TestHelper.InitalizeDecodableBytes(inputSpan); int requiredLength = Base64.GetMaxDecodedFromUtf8Length(inputSpan.Length); Span <byte> expected = new byte[requiredLength]; Assert.Equal(OperationStatus.Done, Base64.DecodeFromUtf8(inputSpan, expected, out int bytesConsumed, out int bytesWritten)); byte[][] input = new byte[10][]; int[] split = { 100, 102, 98, 101, 2, 97, 101, 1, 2, 396 }; int sum = 0; for (int i = 0; i < split.Length; i++) { int splitter = split[i]; input[i] = inputSpan.Slice(sum, splitter).ToArray(); sum += splitter; } Assert.Equal(1000, sum); var(first, last) = BufferList.Create(input); var output = new TestOutput(); Base64Experimental.Utf8ToBytesDecoder.Pipe(new ReadOnlyBuffer <byte>(first, 0, last, last.Memory.Length), output); var expectedArray = expected.ToArray(); var array = output.GetBuffer.ToArray(); Assert.True(expected.SequenceEqual(output.GetBuffer.Slice(0, requiredLength))); }
public static ReadOnlyBytes CreateRob(params byte[][] buffers) { if (buffers.Length == 1) { return(new ReadOnlyBytes(buffers[0])); } var(first, last) = BufferList.Create(buffers); return(new ReadOnlyBytes(first, last)); }
public void SequencePositionOfMultiSegment() { var(first, last) = BufferList.Create( new byte[] { 1, 2 }, new byte[] { 3, 4 } ); var bytes = new ReadOnlySequence <byte>(first, 0, last, last.Memory.Length); Assert.Equal(4, bytes.Length); // Static method call to avoid calling instance methods Assert.False(Sequence.PositionOf(bytes, 0).HasValue); for (int i = 0; i < bytes.Length; i++) { var value = (byte)(i + 1); var listPosition = MemoryListExtensions.PositionOf(first, value).GetValueOrDefault(); var(node, index) = listPosition.Get <IMemoryList <byte> >(); if (listPosition != default) { Assert.Equal(value, node.Memory.Span[index]); } var robPosition = BuffersExtensions.PositionOf(bytes, value); var robSequencePosition = Sequence.PositionOf(bytes, value); Assert.Equal(listPosition, robPosition); Assert.Equal(listPosition, robSequencePosition); var robSlice = bytes.Slice(1); robPosition = BuffersExtensions.PositionOf(robSlice, value); robSequencePosition = Sequence.PositionOf(robSlice, value); if (i > 0) { Assert.Equal(listPosition, robPosition); Assert.Equal(listPosition, robSequencePosition); } else { Assert.False(robPosition.HasValue); Assert.False(robSequencePosition.HasValue); } if (listPosition != default) { robSlice = bytes.Slice(listPosition); Assert.Equal(value, robSlice.First.Span[0]); } } }
public void SequencePositionOfMultiSegment() { var(first, last) = BufferList.Create( new byte[] { 1, 2 }, new byte[] { 3, 4 } ); var bytes = new ReadOnlySequence <byte>(first, 0, last, last.Memory.Length); Assert.Equal(4, bytes.Length); // Static method call to avoid calling instance methods Assert.False(Sequence.PositionOf(bytes, 0).HasValue); for (int i = 0; i < bytes.Length; i++) { var value = (byte)(i + 1); var listPosition = MemoryListExtensions.PositionOf(first, value).GetValueOrDefault(); var(node, index) = listPosition.Get <ReadOnlySequenceSegment <byte> >(); if (listPosition.Equals(default))
public void HttpParserSegmentedRob(string requestText) { var parser = new HttpParser(); for (int pivot = 26; pivot < requestText.Length; pivot++) { var front = requestText.Substring(0, pivot); var back = requestText.Substring(pivot); var frontBytes = Encoding.ASCII.GetBytes(front); var endBytes = Encoding.ASCII.GetBytes(back); var(first, last) = BufferList.Create(frontBytes, endBytes); var buffer = new ReadOnlySequence <byte>(first, 0, last, last.Memory.Length); var request = new Request(); try { Assert.True(parser.ParseRequestLine(ref request, buffer, out var consumed)); Assert.Equal(25, consumed); var unconsumed = buffer.Slice(consumed); Assert.True(parser.ParseHeaders(ref request, unconsumed, out consumed)); Assert.Equal(8, consumed); } catch { throw; } // request line Assert.Equal(Http.Method.Get, request.Method); Assert.Equal(Http.Version.Http11, request.Version); Assert.Equal("/plaintext", request.Path); // headers Assert.Equal(1, request.Headers.Count); Assert.True(request.Headers.ContainsKey("N")); Assert.Equal("V", request.Headers["N"]); } }