public void ReadBinary() { var reader = new AmqpReader(_encodedBytes_1MB); Assert.True(reader.MoveNext() == AmqpToken.Binary); Assert.AreEqual(AmqpToken.Binary, reader.CurrentType); Assert.True(reader.Bytes.SequenceEqual(_randomBytes1_MB)); }
public int ArrayInt32Decode_1K_SBA_ToArray() { var reader = new AmqpReader(EncodedInt32Array1K); reader.MoveNext(); int[] ints = reader.GetInt32Array(); return(ints.Length); }
public int Bytes_Decode_SBA_ToArray() { var reader = new AmqpReader(EncodedBytes1MB); reader.MoveNext(); var bytes = reader.Bytes.ToArray(); return(bytes.Length); }
public ReadOnlySpan <byte> Bytes_Decode_SBA() { var reader = new AmqpReader(EncodedBytes1MB); reader.MoveNext(); var bytes = reader.Bytes; return(bytes); }
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)); }
public int ArrayInt32Decode_1K_SBA() { var reader = new AmqpReader(EncodedInt32Array1K); reader.MoveNext(); if (!reader.TryGetInt32Array(ScratchInt32Array, out int written)) { throw new InvalidOperationException("buffer too small"); } return(written); }
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)); }
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; } } }
public void ReadDescribedString8() { string value = "ABC"; var descriptor = new DescribedType("GHI", "DEF"); var describedValue = new DescribedType(descriptor, value); _scratchByteBuffer.Reset(); AmqpCodec.EncodeObject(describedValue, _scratchByteBuffer); var encoded = _scratchByteBuffer.Buffer.AsMemory(0, _scratchByteBuffer.WritePos).ToArray(); var encodedBuffer = new ByteBuffer(encoded, 0, encoded.Length); var decoded = (DescribedType)AmqpCodec.DecodeObject(encodedBuffer); Assert.AreEqual(value, decoded.Value); var decodedDescriptor = (DescribedType)decoded.Descriptor; Assert.AreEqual(descriptor.Value, decodedDescriptor.Value); Assert.AreEqual(descriptor.Descriptor, decodedDescriptor.Descriptor); var reader = new AmqpReader(encoded); Assert.AreEqual(AmqpToken.Descriptor, reader.MoveNext()); // let's see what's the type of the descriptor. Oh, it's another descriptor Assert.AreEqual(AmqpToken.Descriptor, reader.MoveNext()); Assert.AreEqual(AmqpToken.String, reader.MoveNext()); var d1 = Encoding.UTF8.GetString(reader.Bytes); Assert.AreEqual(AmqpToken.String, reader.MoveNext()); var d2 = Encoding.UTF8.GetString(reader.Bytes); Assert.AreEqual(AmqpToken.String, reader.MoveNext()); var v1 = Encoding.UTF8.GetString(reader.Bytes); }