Esempio n. 1
0
        public static FrameType Peek(MemoryCursor cursor)
        {
            var bytes = cursor.PeekEnd();
            var value = VariableLengthEncoding.Decode(bytes.Span, out _);

            return(new FrameType(value));
        }
Esempio n. 2
0
        public static StreamId Parse(ReadOnlyMemory <byte> bytes, out ReadOnlyMemory <byte> remainings)
        {
            var id = VariableLengthEncoding.Decode(bytes.Span, out var decodedLength);

            remainings = bytes.Slice(decodedLength);

            return(new StreamId(id));
        }
Esempio n. 3
0
        public static Error ParseTransport(ReadOnlyMemory <byte> bytes, out ReadOnlyMemory <byte> remainings)
        {
            var code = VariableLengthEncoding.Decode(bytes.Span, out var decodedLength);

            remainings = bytes.Slice(decodedLength);

            return(new Error(code, true, false));
        }
Esempio n. 4
0
        public static FrameType Parse(ReadOnlyMemory <byte> bytes, out ReadOnlyMemory <byte> remainings)
        {
            var code = VariableLengthEncoding.Decode(bytes.Span, out var decodedLength);

            remainings = bytes.Slice(decodedLength);

            return(new FrameType(code));
        }
        public void ReadValue_ResultIsExpected(string bytes, ulong expectedValue, int expectedLength)
        {
            //Arrange
            //Act
            var resultValue = VariableLengthEncoding.Decode(Utils.ParseHexString(bytes), out var resultLength);

            //Assert
            Assert.Equal(expectedValue, resultValue);
            Assert.Equal(expectedLength, resultLength);
        }
Esempio n. 6
0
            private int ReadLength()
            {
                var length = VariableLengthEncoding.Decode(remainings.Span, out var decodedLength);

                if (length > int.MaxValue)
                {
                    throw new EncodingException();
                }

                remainings = remainings.Slice(decodedLength);

                return((int)length);
            }
Esempio n. 7
0
        public static bool TrySlice(MemoryCursor cursor, FrameType expected)
        {
            var bytes = cursor.PeekEnd();
            var type  = VariableLengthEncoding.Decode(bytes.Span, out var decodedLength);

            if (type != expected.type)
            {
                return(false);
            }

            cursor.Move(decodedLength);

            return(true);
        }
        public static bool TrySlice(MemoryCursor cursor, TransportParameterType expected)
        {
            var bytes = cursor.PeekEnd();
            var id    = VariableLengthEncoding.Decode(bytes.Span, out var decodedLength);

            if (id != expected.id)
            {
                return(false);
            }

            cursor.Move(decodedLength);

            return(true);
        }