public void TestDynamicObject() { var reg = new MessageRegistry(); var typeRegistry = TypeRegistry.CreateDefault(); var ser = new DefaultSerializer<SubMessage>(reg, typeRegistry); var r = new DynamicSerializer(reg, typeRegistry); using (var buf = new ThreadSafeWriteQueue(1024)) { dynamic src = new SubMessage { MessageId = ser.MessageId, A = 1, B = 2 }; r.Serialize(buf, src); dynamic a = new { }; r.Deserialize(buf, buf.ReadMessage(), a); } }
public void EmptyString() { var r = new DefaultSerializer<SubMessage>(this.messageRegistry, this.typeRegistry); using (var buf = new ThreadSafeWriteQueue(1024)) { var orig = new SubMessage { Text = string.Empty, }; r.Serialize(buf, orig); SubMessage message = new SubMessage(); r.Deserialize(buf, buf.ReadMessage(), message); Assert.AreEqual(orig.MessageId, message.MessageId); Assert.IsTrue(string.IsNullOrEmpty(message.Text)); } }
public void TwoMessages() { var r = new DefaultSerializer<SubMessage>(this.messageRegistry, this.typeRegistry); using (var buf = new ThreadSafeWriteQueue(1024)) { var orig = new SubMessage { MessageId = int.MaxValue, A = int.MinValue, B = float.Epsilon, C = uint.MinValue, Byte = 1, Text = "aaaвпаав", }; var orig2 = new SubMessage { MessageId = int.MaxValue, A = int.MaxValue, B = float.MaxValue, C = uint.MaxValue, Byte = 255, Text = "впаавzz", }; r.Serialize(buf, orig); r.Serialize(buf, orig2); SubMessage message = new SubMessage(); r.Deserialize(buf, buf.ReadMessage(), message); Assert.AreEqual(orig.MessageId, message.MessageId); Assert.AreEqual(orig.A, message.A); Assert.AreEqual(orig.B, message.B); Assert.AreEqual(orig.C, message.C); Assert.AreEqual(orig.Text, message.Text); r.Deserialize(buf, buf.ReadMessage(), message); Assert.AreEqual(orig2.MessageId, message.MessageId); Assert.AreEqual(orig2.A, message.A); Assert.AreEqual(orig2.B, message.B); Assert.AreEqual(orig2.C, message.C); Assert.AreEqual(orig2.Text, message.Text); } }
public void ThreeBytesString() { var r = new DefaultSerializer<SubMessage>(this.messageRegistry, this.typeRegistry); using (var buf = new ThreadSafeWriteQueue(1024)) { var orig = new SubMessage { Text = "aaa", }; r.Serialize(buf, orig); r.Serialize(buf, orig); SubMessage message = new SubMessage(); r.Deserialize(buf, buf.ReadMessage(), message); Assert.AreEqual(orig.MessageId, message.MessageId); Assert.AreEqual(orig.Text, message.Text); r.Deserialize(buf, buf.ReadMessage(), message); Assert.AreEqual(orig.MessageId, message.MessageId); Assert.AreEqual(orig.Text, message.Text); } }