示例#1
0
            public static TransportMessage Deserialize(byte[] bytes)
            {
                var bufferReader         = new ProtoBufferReader(bytes, bytes.Length);
                var readTransportMessage = bufferReader.ReadTransportMessage();

                return(readTransportMessage);
            }
        public void MeasureReadPerformance()
        {
            var transportMessage = TestDataBuilder.CreateTransportMessage <FakeCommand>();

            var bufferWriter = new ProtoBufferWriter();

            bufferWriter.WriteTransportMessage(transportMessage);

            var bufferReader = new ProtoBufferReader(bufferWriter.Buffer, bufferWriter.Position);

            bufferReader.ReadTransportMessage();

            const int count = 100_000_000;

            using (Measure.Throughput(count))
            {
                for (var i = 0; i < count; i++)
                {
                    bufferReader.Reset();
                    bufferReader.ReadTransportMessage();
                }
            }
        }
        public void should_deserialize_1_4_1_transport_messages()
        {
            var content         = new MemoryStream(new byte[] { 1, 2, 3 });
            var originatorInfo  = new OriginatorInfo(new PeerId("peer"), "endpoint", "MACHINEXXX", "username");
            var messageId       = new MessageId(Guid.Parse("ce0ac850-a9c5-e511-932e-d8e94a2d2418"));
            var expectedMessage = new TransportMessage(new MessageTypeId("lol"), content, originatorInfo)
            {
                Id = messageId
            };

            var stream       = GetTransportMessageStream_1_4_1();
            var bufferReader = new ProtoBufferReader(stream.GetBuffer(), (int)stream.Length);

            var message = bufferReader.ReadTransportMessage();

            message.ShouldHaveSamePropertiesAs(expectedMessage);
        }
        public void should_read_WasPersisted_as_null_for_older_versions()
        {
            var content         = new MemoryStream(new byte[] { 1, 2, 3 });
            var originatorInfo  = new OriginatorInfo(new PeerId("peer"), "endpoint", "MACHINEXXX", "username");
            var messageId       = new MessageId(Guid.Parse("ce0ac850-a9c5-e511-932e-d8e94a2d2418"));
            var expectedMessage = new TransportMessage(new MessageTypeId("lol"), content, originatorInfo)
            {
                Id = messageId, WasPersisted = false
            };

            var stream       = GetTransportMessageStream_1_4_1();
            var bufferReader = new ProtoBufferReader(stream.GetBuffer(), (int)stream.Length);

            var message = bufferReader.ReadTransportMessage();

            message.ShouldHaveSamePropertiesAs(expectedMessage, "WasPersisted");
            message.WasPersisted.ShouldBeNull();
        }
        public void should_read_message()
        {
            var transportMessage = TestDataBuilder.CreateTransportMessage <FakeCommand>();

            var bufferWriter = new ProtoBufferWriter();

            bufferWriter.WriteTransportMessage(transportMessage);

            var bufferReader = new ProtoBufferReader(bufferWriter.Buffer, bufferWriter.Position);
            var deserialized = bufferReader.ReadTransportMessage();

            deserialized.Id.ShouldEqual(transportMessage.Id);
            deserialized.MessageTypeId.ShouldEqual(transportMessage.MessageTypeId);
            deserialized.GetContentBytes().ShouldEqual(transportMessage.GetContentBytes());
            deserialized.Originator.ShouldEqualDeeply(transportMessage.Originator);
            deserialized.Environment.ShouldEqual(transportMessage.Environment);
            deserialized.WasPersisted.ShouldEqual(transportMessage.WasPersisted);
        }
        public void should_read_message_from_protobuf()
        {
            var transportMessage = TestDataBuilder.CreateTransportMessage <FakeCommand>();

            var stream = new MemoryStream();

            Serializer.Serialize(stream, transportMessage);

            var bufferReader = new ProtoBufferReader(stream.GetBuffer(), (int)stream.Length);
            var deserialized = bufferReader.ReadTransportMessage();

            deserialized.Id.ShouldEqual(transportMessage.Id);
            deserialized.MessageTypeId.ShouldEqual(transportMessage.MessageTypeId);
            deserialized.GetContentBytes().ShouldEqual(transportMessage.GetContentBytes());
            deserialized.Originator.ShouldEqualDeeply(transportMessage.Originator);
            deserialized.Environment.ShouldEqual(transportMessage.Environment);
            deserialized.WasPersisted.ShouldEqual(transportMessage.WasPersisted);
        }
        public void should_read_message_with_persistent_peer_ids()
        {
            var transportMessage = TestDataBuilder.CreateTransportMessage <FakeCommand>();

            transportMessage.PersistentPeerIds = new List <PeerId>
            {
                new PeerId("Abc.Testing.A"),
                new PeerId("Abc.Testing.B"),
            };

            var bufferWriter = new ProtoBufferWriter();

            bufferWriter.WriteTransportMessage(transportMessage);
            bufferWriter.WritePersistentPeerIds(transportMessage, transportMessage.PersistentPeerIds);

            var bufferReader = new ProtoBufferReader(bufferWriter.Buffer, bufferWriter.Position);
            var deserialized = bufferReader.ReadTransportMessage();

            deserialized.Id.ShouldEqual(transportMessage.Id);
            deserialized.MessageTypeId.ShouldEqual(transportMessage.MessageTypeId);
            deserialized.PersistentPeerIds.ShouldEqual(transportMessage.PersistentPeerIds);
        }
        public void should_read_empty_message()
        {
            var transportMessage = new EmptyCommand().ToTransportMessage();

            var bufferWriter = new ProtoBufferWriter();

            bufferWriter.WriteTransportMessage(transportMessage);

            var bufferReader = new ProtoBufferReader(bufferWriter.Buffer, bufferWriter.Position);
            var deserialized = bufferReader.ReadTransportMessage();

            deserialized.Id.ShouldEqual(transportMessage.Id);
            deserialized.MessageTypeId.ShouldEqual(transportMessage.MessageTypeId);
            deserialized.Content.ShouldEqual(Stream.Null);
            deserialized.Originator.ShouldEqualDeeply(transportMessage.Originator);
            deserialized.Environment.ShouldEqual(transportMessage.Environment);
            deserialized.WasPersisted.ShouldEqual(transportMessage.WasPersisted);

            var deserializedMessage = deserialized.ToMessage() as EmptyCommand;

            deserializedMessage.ShouldNotBeNull();
        }