private void WriteTransportMessageAndSendToPeers(TransportMessage transportMessage, List <Peer> peers, SendContext context, ProtoBufferWriter bufferWriter) { bufferWriter.Reset(); bufferWriter.WriteTransportMessage(transportMessage, _environment); if (context.PersistencePeer == null && transportMessage.IsPersistTransportMessage) { bufferWriter.WritePersistentPeerIds(transportMessage, transportMessage.PersistentPeerIds); } foreach (var target in peers) { var isPersistent = context.WasPersisted(target.Id); bufferWriter.SetWasPersisted(isPersistent); SendToPeer(transportMessage, bufferWriter, target); } if (context.PersistencePeer != null) { bufferWriter.WritePersistentPeerIds(transportMessage, context.PersistentPeerIds); SendToPeer(transportMessage, bufferWriter, context.PersistencePeer); } }
public void should_serialize_transport_message_with_persistent_peer_ids_and_read_from_protobuf() { var transportMessage = TestDataBuilder.CreateTransportMessage <FakeCommand>(); transportMessage.PersistentPeerIds = new List <PeerId> { new PeerId("Abc.Testing.A"), new PeerId("Abc.Testing.B"), }; var writer = new ProtoBufferWriter(); writer.WriteTransportMessage(transportMessage); writer.WritePersistentPeerIds(transportMessage, transportMessage.PersistentPeerIds); var deserialized = Serializer.Deserialize <TransportMessage>(new MemoryStream(writer.Buffer, 0, writer.Position)); deserialized.Id.ShouldEqual(transportMessage.Id); deserialized.MessageTypeId.ShouldEqual(transportMessage.MessageTypeId); deserialized.PersistentPeerIds.ShouldBeEquivalentTo(transportMessage.PersistentPeerIds); }
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); }