示例#1
0
        public void Test_ToUInt16()
        {
            var        converter = new DefaultConverter();
            var        actual    = converter.ToUInt16(_buffer, 2);
            const uint expected  = 5u;

            Assert.AreEqual(expected, actual);
        }
示例#2
0
        public void Test_ToUInt16_NoNboSpecified(ushort value)
        {
            var converter = new DefaultConverter();

            var bytes = BitConverter.GetBytes(value);

            bytes = bytes.Reverse().ToArray();

            var actual = converter.ToUInt16(bytes.AsSpan());

            Assert.Equal(value, actual);
        }
示例#3
0
        public void Test_ToUInt16(ushort value, bool useNbo)
        {
            var converter = new DefaultConverter();

            var bytes = BitConverter.GetBytes(value);

            if (useNbo)
            {
                bytes = bytes.Reverse().ToArray();
            }

            var actual = converter.ToUInt16(bytes.AsSpan(), useNbo);

            Assert.Equal(value, actual);
        }
示例#4
0
        public void When_ByteArray_Is_Stored_With_Legacy_Flags_It_Is_Decoded_As_A_ByteArray()
        {
            var legacyByteArray = new byte[]
            {
                129, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 8, 0,
                0, 0, 5, 19, 185, 8, 248, 3, 104, 208, 188, 0,
                0, 250, 82, 116, 101, 115, 116
            };

            var converter = new DefaultConverter();
            var format    = new byte();

            var temp = converter.ToByte(legacyByteArray, 24);

            converter.SetBit(ref format, 0, converter.GetBit(temp, 0));
            converter.SetBit(ref format, 1, converter.GetBit(temp, 1));
            converter.SetBit(ref format, 2, converter.GetBit(temp, 2));
            converter.SetBit(ref format, 3, converter.GetBit(temp, 3));

            var compression = new byte();

            converter.SetBit(ref compression, 4, converter.GetBit(temp, 4));
            converter.SetBit(ref compression, 5, converter.GetBit(temp, 5));
            converter.SetBit(ref compression, 6, converter.GetBit(temp, 6));

            var flags = new Flags
            {
                DataFormat  = (DataFormat)format,
                Compression = (Compression)compression,
                TypeCode    = (TypeCode)(converter.ToUInt16(legacyByteArray, 26) & 0xff),
            };

            var transcoder = new DefaultTranscoder(new DefaultConverter());
            var result     = transcoder.Decode <byte[]>(legacyByteArray.AsMemory(28, 4), flags, OpCode.Get);

            Assert.Equal("test", Encoding.UTF8.GetString(result));
        }