Example #1
0
        public void LEB128_Int32(int value, int byteCount)
        {
            // determine the number of bytes the encoding will take
            int encodedByteCount = Leb128EncodingHelper.GetByteCount(value);

            Assert.Equal(byteCount, encodedByteCount);

            // write to array
            byte[] buffer_array = new byte[encodedByteCount];
            int    count_array  = Leb128EncodingHelper.Write(buffer_array, 0, value);

            Assert.Equal(byteCount, count_array);

            // write to span
            byte[] buffer_span = new byte[encodedByteCount];
            int    count_span  = Leb128EncodingHelper.Write(buffer_span.AsSpan(), value);

            Assert.Equal(byteCount, count_span);

            // read from array
            int reverse_array = Leb128EncodingHelper.ReadInt32(buffer_array, 0, count_array, out int size_array);

            Assert.Equal(byteCount, size_array);
            Assert.Equal(value, reverse_array);

            // read from stream
            Stream ms             = new MemoryStream(buffer_array);
            int    reverse_stream = Leb128EncodingHelper.ReadInt32(ms);

            Assert.Equal(byteCount, ms.Position);
            Assert.Equal(value, reverse_stream);
        }
Example #2
0
        public void LEB128_Int32(int value, int byteCount)
        {
            int count1  = Leb128EncodingHelper.GetByteCount(value);
            int count2  = Leb128EncodingHelper.Write(mBuffer, 0, value);
            int reverse = Leb128EncodingHelper.ReadInt32(mBuffer, 0, count2, out int size);

            Assert.Equal(byteCount, count1);
            Assert.Equal(byteCount, count2);
            Assert.Equal(byteCount, size);
            Assert.Equal(value, reverse);
        }