示例#1
0
        public void Write_And_Read_Multiple_Times()
        {
            var writer = new MqttBufferWriter(4096, 65535);

            writer.WriteString("A relative short string.");
            writer.WriteBinaryData(new byte[1234]);
            writer.WriteByte(0x01);
            writer.WriteByte(0x02);
            writer.WriteVariableByteInteger(5647382);
            writer.WriteString("A relative short string.");
            writer.WriteVariableByteInteger(8574489);
            writer.WriteBinaryData(new byte[48]);
            writer.WriteByte(2);
            writer.WriteByte(0x02);
            writer.WriteString("fjgffiogfhgfhoihgoireghreghreguhreguireoghreouighreouighreughreguiorehreuiohruiorehreuioghreug");
            writer.WriteBinaryData(new byte[3]);

            var readPayload = new ArraySegment <byte>(writer.GetBuffer(), 0, writer.Length).ToArray();

            var reader = new MqttBufferReader();

            reader.SetBuffer(readPayload, 0, readPayload.Length);

            for (var i = 0; i < 100000; i++)
            {
                reader.Seek(0);

                reader.ReadString();
                reader.ReadBinaryData();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadVariableByteInteger();
                reader.ReadString();
                reader.ReadVariableByteInteger();
                reader.ReadBinaryData();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadString();
                reader.ReadBinaryData();
            }
        }
示例#2
0
        public void Use_All_Data_Types()
        {
            var writer = new MqttBufferWriter(4096, 65535);

            writer.WriteString("AString");
            writer.WriteByte(0x1);
            writer.WriteByte(0x0);
            writer.WriteByte(0x1);
            writer.WriteVariableByteInteger(1234U);
            writer.WriteVariableByteInteger(9876U);

            var buffer = writer.GetBuffer();

            var reader = new MqttBufferReader();

            reader.SetBuffer(buffer, 0, writer.Length);

            Assert.AreEqual("AString", reader.ReadString());
            Assert.IsTrue(reader.ReadByte() == 1);
            Assert.IsTrue(reader.ReadByte() == 0);
            Assert.IsTrue(reader.ReadByte() == 1);
            Assert.AreEqual(1234U, reader.ReadVariableByteInteger());
            Assert.AreEqual(9876U, reader.ReadVariableByteInteger());
        }
示例#3
0
        public void Read_100_000_Messages()
        {
            var reader = new MqttBufferReader();

            reader.SetBuffer(_readPayload, 0, _readPayload.Length);

            for (var i = 0; i < 100000; i++)
            {
                reader.Seek(0);

                reader.ReadString();
                reader.ReadBinaryData();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadVariableByteInteger();
                reader.ReadString();
                reader.ReadVariableByteInteger();
                reader.ReadBinaryData();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadString();
                reader.ReadBinaryData();
            }
        }
示例#4
0
        public MqttV5PropertiesReader(MqttBufferReader body)
        {
            _body = body ?? throw new ArgumentNullException(nameof(body));

            if (!body.EndOfStream)
            {
                _length = (int)body.ReadVariableByteInteger();
            }
            else
            {
                _length = 0;
            }

            _targetOffset = body.Position + _length;

            CollectedUserProperties = null;
            CurrentPropertyId       = MqttPropertyId.None;
        }
示例#5
0
        public void Encode_Four_Byte_Integer()
        {
            var writer = new MqttBufferWriter(4, 4);
            
            for (uint value = 0; value < 268435455; value++)
            {
                writer.WriteVariableByteInteger(value);
                
                var buffer = writer.GetBuffer();
                
                var reader = new MqttBufferReader();
                reader.SetBuffer(buffer, 0, writer.Length);
                var checkValue = reader.ReadVariableByteInteger();

                Assert.AreEqual(value, checkValue);
                
                writer.Reset(0);
            }
        }
示例#6
0
 public uint ReadSubscriptionIdentifier()
 {
     return(_body.ReadVariableByteInteger());
 }