コード例 #1
0
        protected override IMqttPacketBodyReader ReaderFactory(byte[] data)
        {
            var result = new SpanBasedMqttPacketBodyReader();

            result.SetBuffer(data);
            return(result);
        }
コード例 #2
0
        public void TestTryDeserialize()
        {
            var serializer = new MqttPacketFormatterAdapter(MqttProtocolVersion.V311);

            var buffer = serializer.Encode(new MqttPublishPacket()
            {
                Topic = "a", Payload = new byte[5]
            });

            var sequence = new ReadOnlySequence <byte>(buffer.Array, buffer.Offset, buffer.Count);

            var            part = sequence;
            MqttBasePacket packet;
            var            consumed = part.Start;
            var            observed = part.Start;
            var            result   = false;
            var            read     = 0;

            var reader = new SpanBasedMqttPacketBodyReader();

            part   = sequence.Slice(sequence.Start, 0); // empty message should fail
            result = serializer.TryDecode(reader, part, out packet, out consumed, out observed, out read);
            Assert.IsFalse(result);


            part   = sequence.Slice(sequence.Start, 1); // partial fixed header should fail
            result = serializer.TryDecode(reader, part, out packet, out consumed, out observed, out read);
            Assert.IsFalse(result);

            part   = sequence.Slice(sequence.Start, 4); // partial body should fail
            result = serializer.TryDecode(reader, part, out packet, out consumed, out observed, out read);
            Assert.IsFalse(result);

            part   = sequence; // complete msg should work
            result = serializer.TryDecode(reader, part, out packet, out consumed, out observed, out read);
            Assert.IsTrue(result);
        }
コード例 #3
0
ファイル: ReaderExtensions.cs プロジェクト: Marcel-B/Mqtt
 public static bool TryDecode(this MqttPacketFormatterAdapter formatter,
                              SpanBasedMqttPacketBodyReader reader,
                              in ReadOnlySequence <byte> input,