Exemple #1
0
        public void ReadArrayInt32()
        {
            var reader = new AmqpReader(_encodedInt32_1M);

            Assert.True(reader.MoveNext() == AmqpToken.Array);
            Assert.AreEqual(AmqpToken.Array, reader.CurrentType);
            int[] decoded = reader.GetInt32Array();
            Assert.True(_randomInt32_1M.AsSpan().SequenceEqual(decoded));
        }
Exemple #2
0
        public void ReadSpanInt32()
        {
            var reader = new AmqpReader(_encodedInt32_1M);

            Assert.True(reader.MoveNext() == AmqpToken.Array);
            Assert.AreEqual(AmqpToken.Array, reader.CurrentType);

            if (!reader.TryGetInt32Array(ScratchInt32Array, out int written))
            {
                throw new InvalidOperationException("buffer too small");
            }

            Assert.True(ScratchInt32Array.AsSpan(0, written).SequenceEqual(_randomInt32_1M));
        }
Exemple #3
0
        public void ComplexReader()
        {
            byte[] buffer = new byte[1024];
            AmqpWriter.TryWriteString(buffer, s_text, out int written);

            var reader = new AmqpReader(buffer.AsSpan().Slice(0, written));

            while (reader.MoveNext() != AmqpToken.EndOfData)
            {
                switch (reader.CurrentType)
                {
                case AmqpToken.String:
                    Assert.AreEqual(s_text, Encoding.UTF8.GetString(reader.Bytes));
                    break;
                }
            }
        }