Ejemplo n.º 1
0
		public void SampleMessageFieldParams()
		{
			var defaultSerializer = new DefaultSerializer<SampleMessage>(this.messageRegistry, this.typeRegistry);
			var d = new MessageDispatcher<SampleApiClass>(this.messageRegistry, this.typeRegistry);
			using (var buf = new ThreadSafeWriteQueue(1024))
			{
				var orig = new SampleMessage { MessageId = defaultSerializer.MessageId, A = 10 };
				defaultSerializer.Serialize(buf, orig);
				var pos = buf.ReadMessage();
				Assert.IsTrue(d.Dispatch(buf, pos, defaultSerializer.MessageId, new SampleApiClass()));
			}
		}
Ejemplo n.º 2
0
		public void BinarySerialization()
		{
			var reg = new MessageRegistry();
			var ser = new DefaultSerializer<SubMessage>(reg, new TypeRegistry( new[] { TypeRegistry.StandartTypes, new[] { new VectorXYZBinarySerializer() }}));

			using (var buf = new ThreadSafeWriteQueue(1024))
			{
				var src = new SubMessage { Vector3 = new Vector3(1.1f, 2.2f, 3.3f) };
				ser.Serialize(buf, src);
				var dst = new SubMessage();
				ser.Deserialize(buf, buf.ReadMessage(), dst);
				Assert.AreEqual(src.Vector3, dst.Vector3);
			}
		}
Ejemplo n.º 3
0
		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);
			}
		}
Ejemplo n.º 4
0
		public void TestVec4()
		{
			var r = new DefaultSerializer<SingleMessage<Vector4>>(this.messageRegistry, this.typeRegistry,4);
			using (var buf = new ThreadSafeWriteQueue(1024))
			{
				var orig = new SingleMessage<Vector4> { MessageId = r.MessageId, A = new Vector4(1.1f, 2.2f, 3.3f,( 4.4f)) };
				r.Serialize(buf, orig);

				SingleMessage<Vector4> message = new SingleMessage<Vector4>();

				r.Deserialize(buf, buf.ReadMessage(), message);
				Assert.AreEqual(orig.MessageId, message.MessageId);
				Assert.AreEqual(orig.A, message.A);
			}

		}
Ejemplo n.º 5
0
		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));
			}
		}
Ejemplo n.º 6
0
		public void TestTable()
		{
			var reg = new MessageRegistry();
			var a = new LuaSerializer(reg, LuaTypeRegistry.CreateDefault());
			var ser = new DefaultSerializer<SubMessage>(reg, TypeRegistry.CreateDefault());

			using (var buf = new ThreadSafeWriteQueue(1024))
			{
				var dictionary = new Dictionary<LuaObject, LuaObject> { };
				dictionary.Add(LuaObject.FromString("MessageId"), LuaObject.FromNumber(ser.MessageId));
				var table = LuaObject.FromTable(dictionary);
				table[LuaObject.FromString("Text")] = LuaObject.FromString("abc");
				a.Send(buf, table);

				int pos = buf.ReadMessage();
				var id = buf.ReadInt32(pos);
				Assert.AreEqual(ser.MessageId, id);

				var table2 = a.Receive(buf, pos);
				Assert.AreEqual(ser.MessageId, table2[LuaObject.FromString("MessageId")].AsNumber());
				Assert.AreEqual(table[LuaObject.FromString("Text")].AsString(), table2[LuaObject.FromString("Text")].AsString());
			}
		}
Ejemplo n.º 7
0
		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);
			}
		}
Ejemplo n.º 8
0
		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);
			}
		}