Esempio n. 1
0
        public void LEB128_UInt32(uint 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
            uint reverse_array = Leb128EncodingHelper.ReadUInt32(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);
            uint   reverse_stream = Leb128EncodingHelper.ReadUInt32(ms);

            Assert.Equal(byteCount, ms.Position);
            Assert.Equal(value, reverse_stream);
        }
Esempio n. 2
0
        public void LEB128_UInt32(uint value, int byteCount)
        {
            int  count1  = Leb128EncodingHelper.GetByteCount(value);
            int  count2  = Leb128EncodingHelper.Write(mBuffer, 0, value);
            uint reverse = Leb128EncodingHelper.ReadUInt32(mBuffer, 0, count2, out int size);

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