Exemplo n.º 1
0
        public void TryWrite_BufferNotSizedCorrectly_EightByteLimit()
        {
            long        longToEncode = 1073741824;
            Span <byte> span         = new Span <byte>(new byte[1]);
            bool        isSuccess    = VariableLengthIntegerHelper.TryWrite(span,
                                                                            longToEncode, out int bytesWritten);

            Assert.False(isSuccess);
            Assert.Equal(0, bytesWritten);
        }
Exemplo n.º 2
0
        public void TryWrite_BufferNotEmpty_OneByteLimit(long longToEncode)
        {
            Span <byte> span      = new Span <byte>(new byte[1]);
            bool        isSuccess = VariableLengthIntegerHelper.TryWrite(span,
                                                                         longToEncode, out int bytesWritten);

            Assert.True(isSuccess);
            Assert.Equal(1, bytesWritten);
            Assert.Equal(longToEncode, span[0]);
        }
Exemplo n.º 3
0
        public void TryWrite_BufferEmpty()
        {
            Span <byte> span         = new Span <byte>();
            long        longToEncode = 1;
            bool        isSuccess    = VariableLengthIntegerHelper.TryWrite(span,
                                                                            longToEncode, out int bytesWritten);

            Assert.False(isSuccess);
            Assert.Equal(0, bytesWritten);
        }
Exemplo n.º 4
0
        public void TryWrite_BufferNotEmpty_EightByteLimit(long longToEncode,
                                                           byte[] expected)
        {
            Span <byte> span      = new Span <byte>(new byte[8]);
            bool        isSuccess = VariableLengthIntegerHelper.TryWrite(span,
                                                                         longToEncode, out int bytesWritten);

            Assert.True(isSuccess);
            Assert.Equal(8, bytesWritten);
            Assert.Equal(expected, span.ToArray());
        }