public MultiDeserializer(Configure config, Conventions conventions, IMessageSerializer defaultSerializer, IMessageMapper mapper, LogicalMessageFactory logicalMessageFactory, MessageMetadataRegistry metadataRegistry) { _defaultSerializer = defaultSerializer; _logicalMessageFactory = logicalMessageFactory; _metadataRegistry = metadataRegistry; var json = new JsonMessageSerializer(mapper); serializers.Add(json.ContentType, json); var bson = new BsonMessageSerializer(mapper); serializers.Add(bson.ContentType, bson); var binary = new BinaryMessageSerializer(); serializers.Add(binary.ContentType, binary); var xml = new XmlMessageSerializer(mapper, conventions); List <Type> messageTypes = config.TypesToScan.Where(conventions.IsMessageType).ToList(); xml.Initialize(messageTypes); serializers.Add(xml.ContentType, xml); if (!serializers.ContainsKey(_defaultSerializer.ContentType)) { serializers.Add(_defaultSerializer.ContentType, _defaultSerializer); } }
public MessageSerializerAdapter() { var mapper = new MessageMapper(); var json = new JsonMessageSerializer(mapper); _serializers.Add(json.ContentType, json); var bson = new BsonMessageSerializer(mapper); _serializers.Add(bson.ContentType, bson); var binary = new BinaryMessageSerializer(); _serializers.Add(binary.ContentType, binary); IList <Type> messageTypes = Configure.TypesToScan.Where(MessageConventionExtensions.IsMessageType).ToList(); var xml = new XmlMessageSerializer(mapper); xml.Initialize(messageTypes); _serializers.Add(xml.ContentType, xml); _defaultSerializer = xml; if (!_serializers.ContainsKey(_defaultSerializer.ContentType)) { _serializers.Add(_defaultSerializer.ContentType, _defaultSerializer); } }
public void TestMethod() { int msgCount = 5000; IMessageSerializer json = new JsonMessageSerializer(); IMessageSerializer bson = new BsonMessageSerializer(); long elapsed1; long elapsed2; Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < msgCount; i++) { IMessage msg = new MessageSerDes() { Content = "Hello world people" }; using (MemoryStream ms = new MemoryStream()) { json.Serialize(msg, ms); if (ms.CanSeek) ms.Seek(0, SeekOrigin.Begin); var des = json.Deserialize(ms); if ((des as MessageSerDes).Content != (msg as MessageSerDes).Content || (des as MessageSerDes).Id != (msg as MessageSerDes).Id || (des as MessageSerDes).Age != (msg as MessageSerDes).Age) Assert.Fail(); } msg = null; } sw.Stop(); elapsed1 = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 0; i < msgCount; i++) { IMessage msg = new MessageSerDes() { Content = "Hello world people" }; using (MemoryStream ms = new MemoryStream()) { bson.Serialize(msg, ms); if (ms.CanSeek) ms.Seek(0, SeekOrigin.Begin); var des = bson.Deserialize(ms); if ((des as MessageSerDes).Content != (msg as MessageSerDes).Content || (des as MessageSerDes).Id != (msg as MessageSerDes).Id || (des as MessageSerDes).Age != (msg as MessageSerDes).Age) Assert.Fail(); } msg = null; } sw.Stop(); elapsed2 = sw.ElapsedMilliseconds; Assert.AreNotEqual(elapsed1, elapsed2); }
public void Setup() { Serializer = new BsonMessageSerializer(MessageMapper); }
public void TestMethod() { int msgCount = 5000; IMessageSerializer json = new JsonMessageSerializer(); IMessageSerializer bson = new BsonMessageSerializer(); long elapsed1; long elapsed2; Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < msgCount; i++) { IMessage msg = new MessageSerDes() { Content = "Hello world people" }; using (MemoryStream ms = new MemoryStream()) { json.Serialize(msg, ms); if (ms.CanSeek) { ms.Seek(0, SeekOrigin.Begin); } var des = json.Deserialize(ms); if ((des as MessageSerDes).Content != (msg as MessageSerDes).Content || (des as MessageSerDes).Id != (msg as MessageSerDes).Id || (des as MessageSerDes).Age != (msg as MessageSerDes).Age) { Assert.Fail(); } } msg = null; } sw.Stop(); elapsed1 = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 0; i < msgCount; i++) { IMessage msg = new MessageSerDes() { Content = "Hello world people" }; using (MemoryStream ms = new MemoryStream()) { bson.Serialize(msg, ms); if (ms.CanSeek) { ms.Seek(0, SeekOrigin.Begin); } var des = bson.Deserialize(ms); if ((des as MessageSerDes).Content != (msg as MessageSerDes).Content || (des as MessageSerDes).Id != (msg as MessageSerDes).Id || (des as MessageSerDes).Age != (msg as MessageSerDes).Age) { Assert.Fail(); } } msg = null; } sw.Stop(); elapsed2 = sw.ElapsedMilliseconds; Assert.AreNotEqual(elapsed1, elapsed2); }