public void message_should_work() { var context = MachineContext.Create(b => b .RegisterIdentities(typeof(UserId) /*, typeof(SuperUserId)*/) ); var metadata = new MessageMetadata(); metadata.Receivers = new List <IIdentity>() { new UserId() { Value = "hello" }, new UserId() { Value = "hello232" }, new UserId() { Value = "hello232dfhdghdgh" }, }; var bytes = ProtobufSerializer.SerializeProtocalBuffer(metadata, context.Serializer.Model); var back = ProtobufSerializer.DeserializeProtocalBuffer <MessageMetadata>(bytes, context.Serializer.Model); }
/// <summary> /// Serializes, decerializes and checks that objects are equal /// </summary> private void AssertSerializedAndDeserialized <TObject>(TObject obj, RuntimeTypeModel model) { byte[] bytes = ProtobufSerializer.SerializeProtocalBuffer(obj, model); var back = ProtobufSerializer.DeserializeProtocalBuffer <TObject>(bytes, model); bool result = ObjectComparer.AreObjectsEqual(obj, back); Assert.That(result, Is.True); }
public void do_tests() { var obj = new SimpleClass(); //obj.Var = 0; obj.D = DateTime.MinValue; var bytes = ProtobufSerializer.SerializeProtocalBuffer(obj); var back = ProtobufSerializer.DeserializeProtocalBuffer <SimpleClass>(bytes); }
public void test_serialization() { var evnt = new MyEvent() { Name = "Dima", Year = "2012" }; //evnt.Metadata = new EventMetadata<MyProcessId>() { MessageId = Guid.NewGuid(), SenderVersion = 45 }; var model = TypeModel.Create(); /* model[typeof(IIdentity)] * .AddSubType(100, typeof(IIdentity<String>)); * * model[typeof(IIdentity<String>)] * .AddSubType(100, typeof(StringId)); * * model[typeof(StringId)] * .AddSubType(100, typeof(MyProcessId));*/ /* model[typeof(IMessageMetadata)] * .AddSubType(100, typeof(IEventMetadata)); * * model[typeof(IEventMetadata)] * .AddSubType(100, typeof(IEventMetadata<MyProcessId>)); * * model[typeof(IEventMetadata<MyProcessId>)] * .AddSubType(100, typeof(EventMetadata<MyProcessId>));*/ /* model[typeof(IMessage)] * .AddSubType(100, typeof(IEvent)); * * model[typeof(IEvent)] * .AddSubType(100, typeof(IEvent<MyProcessId>)); * * model[typeof(IEvent<MyProcessId>)] * .AddSubType(100, typeof(Event<MyProcessId>)); */ model[typeof(IEvent <MyProcessId>)] .AddSubType(100, typeof(MyEvent)); //model.Add(typeof(Event<MyProcessId>), true); var bytes = ProtobufSerializer.SerializeProtocalBuffer(evnt, model); var back = ProtobufSerializer.DeserializeProtocalBuffer <MyEvent>(bytes, model); Assert.That(back.Name, Is.EqualTo(evnt.Name)); Assert.That(back.Year, Is.EqualTo(evnt.Year)); }
public void protobuf_in_bson() { var obj = Developer.Create(); var bytes = ProtobufSerializer.SerializeProtocalBuffer(obj); var doc = new BsonDocument() { { "Hello", "bye" }, { "ProtoBuf", bytes } }; Assert.That(doc["Hello"].AsString, Is.EqualTo("bye")); }
public void protobuf_serialize_and_deserialise_performance() { var obj = Developer.Create(); var watch = Stopwatch.StartNew(); for (int i = 0; i < _iterations; i++) { var bytes = ProtobufSerializer.SerializeProtocalBuffer(obj); var back = ProtobufSerializer.DeserializeProtocalBuffer <Developer>(bytes); } watch.Stop(); Console.WriteLine("Protobuf. Done in {0} msec", watch.ElapsedMilliseconds); }
public void test() { var context = MachineContext.Create(b => b .RegisterIdentities(typeof(UserId) /*, typeof(SuperUserId)*/) ); var metadata = new StateMetadata(); metadata.ProcessId = new UserId() { Value = "hello" }; var bytes = ProtobufSerializer.SerializeProtocalBuffer(metadata, context.Serializer.Model); var back = ProtobufSerializer.DeserializeProtocalBuffer <StateMetadata>(bytes, context.Serializer.Model); }
public void should_serialize_and_deserialize_type_with_identity_field() { var school = new School() { Id = new SchoolId("school-49"), Name = "Minsk", Year = 56, }; var model = TypeModel.Create(); model[typeof(StringId)] .AddSubType(6, typeof(SchoolId)); var bytes = ProtobufSerializer.SerializeProtocalBuffer(school, model); var back = ProtobufSerializer.DeserializeProtocalBuffer <School>(bytes, model); Assert.That(back.Id.Value, Is.EqualTo(school.Id.Value)); Assert.That(back.Name, Is.EqualTo(school.Name)); Assert.That(back.Year, Is.EqualTo(school.Year)); }