public void Teststtt() { var messageFactory = new MessageFactory(typeof(EnvelopeSerializer_Event), typeof(EnvelopeSerializer_Child_Event)); var identityFactory = new IdentityFactory(typeof(EnvelopeSerializer_Id)); var serializer = new ProtobufSerializer(); serializer.RegisterMessages(messageFactory.MessageDefinitions); serializer.RegisterIdentities(identityFactory.IdentityDefinitions); var message1 = new EnvelopeSerializer_Event() { Rate = 0.7, Title = "Muahaha!" }; var packetSerializer = new PacketSerializer(serializer, messageFactory.TagToTypeResolver); var packet = new PacketBuilder(messageFactory.TypeToTagResolver, packetSerializer) .AddMessage(message1) .Build(); var bytes = packet.Serialize(); var back = new Packet(packetSerializer, bytes); var evnt = (EnvelopeSerializer_Event)back.Envelopes.First().Message; Assert.That(evnt.Rate, Is.EqualTo(message1.Rate)); Assert.That(evnt.Title, Is.EqualTo(message1.Title)); }
public void Teststtt() { var messageFactory = new MessageFactory(typeof(TransitionEnvelopeSerializer_Event), typeof(TransitionEnvelopeSerializer_Child_Event)); var identityFactory = new IdentityFactory(typeof(TransitionEnvelopeSerializer_Id)); var serializer = new ProtobufSerializer(); serializer.RegisterMessages(messageFactory.MessageDefinitions); serializer.RegisterIdentities(identityFactory.IdentityDefinitions); var header = new TransitionEnvelopeDataHeader() { MessageTags = new[] { Guid.Parse("74467730-33c0-418a-bd83-963258ce6fa9"), Guid.Parse("f55856e9-66b3-4fd4-9f6a-de9c2606a692") } }; var message1 = new TransitionEnvelopeSerializer_Event() { Rate = 0.7, Title = "Muahaha!" }; var memory = new MemoryStream(); serializer.Model.SerializeWithLengthPrefix(memory, header, header.GetType(), PrefixStyle.Base128, 0); serializer.Model.SerializeWithLengthPrefix(memory, message1, message1.GetType(), PrefixStyle.Fixed32, 0); memory.Position = 0; var back = serializer.Model.DeserializeWithLengthPrefix(memory, null, header.GetType(), PrefixStyle.Base128, 0, null); var backMessage1 = serializer.Model.DeserializeWithLengthPrefix(memory, null, typeof(TransitionEnvelopeSerializer_Event), PrefixStyle.Fixed32, 0, null); }
public MachineContext(IEnumerable <Type> messageTypes, IEnumerable <Type> identityTypes, IDictionary <String, IRouter> routers) { _messageFactory = new MessageFactory(messageTypes); _identityFactory = new IdentityFactory(identityTypes); _serializer = new ProtobufSerializer(); _serializer.RegisterMessages(_messageFactory.MessageDefinitions); _serializer.RegisterIdentities(_identityFactory.IdentityDefinitions); _packetSerializer = new PacketSerializer(_serializer, _messageFactory.TagToTypeResolver); _routerFactory = new RouterFactory(routers); _zeromqContext = new ZMQ.Context(2); }
public void tra_ta_ta() { var messageFactory = new MessageFactory(typeof(TransitionEnvelopeSerializer_Event), typeof(TransitionEnvelopeSerializer_Child_Event)); var identityFactory = new IdentityFactory(typeof(TransitionEnvelopeSerializer_Id)); var serializer = new ProtobufSerializer(); serializer.RegisterMessages(messageFactory.MessageDefinitions); serializer.RegisterIdentities(identityFactory.IdentityDefinitions); var message1 = new TransitionEnvelopeSerializer_Event() { Rate = 0.7, Title = "Muahaha!" }; var transition = new Transition(null, DateTime.Now, new List <IEvent>() { message1, message1, message1, message1, message1, message1, message1, message1 }, null); var watch = Stopwatch.StartNew(); for (int i = 0; i < _iterations; i++) { var envelopeSerializer = new TransitionEnvelopeSerializer(); var envelope = envelopeSerializer.Serialize(messageFactory, serializer, transition); var doc = Serialize(envelope); var envelopeBack = (TransitionEnvelope)Deserialize(doc, typeof(TransitionEnvelope)); var back = envelopeSerializer.Deserialize(messageFactory, serializer, envelopeBack); } watch.Stop(); Console.WriteLine("ProtoBuf. In {0} iterations takes {1} ms", _iterations, watch.ElapsedMilliseconds); // Assert.That(back.Events.Count, Is.EqualTo(transition.Events.Count)); }
private void Test(IEnumerable <Type> messageTypes, IEnumerable <Type> identityType, params Object[] objects) { var map = new Dictionary <Object, byte[]>(); var messageTypeList = messageTypes.ToList(); var identityTypeList = identityType.ToList(); var messageFactory = new MessageFactory(messageTypeList); var identityFactory = new IdentityFactory(identityTypeList); var serializer = new ProtobufSerializer(); serializer.RegisterMessages(messageFactory.MessageDefinitions); serializer.RegisterIdentities(identityFactory.IdentityDefinitions); foreach (var obj in objects) { map[obj] = serializer.Serialize(obj); } // reverse order of messages and identities messageTypeList.Reverse(); identityTypeList.Reverse(); messageFactory = new MessageFactory(messageTypeList); identityFactory = new IdentityFactory(identityTypeList); serializer = new ProtobufSerializer(); serializer.RegisterMessages(messageFactory.MessageDefinitions); serializer.RegisterIdentities(identityFactory.IdentityDefinitions); foreach (object obj in objects) { var back = serializer.Deserialize(map[obj], obj.GetType()); var result = ObjectComparer.AreObjectsEqual(obj, back); Assert.That(result, Is.True); } }