Пример #1
0
            public void Sending_packet_with_array_segment_should_call_raw_client_with_header_appended()
            {
                var c = new FramedClient(rawClient.Object);

                c.SendPacket(new ArraySegment <byte>(new byte[] { 0, 0, 5, 0, 0, 0, 54, 1, 2, 3 }, 6, 1));

                rawClient.Verify(r => r.Send(new byte[] { 5, 0, 0, 0, 54 }));
            }
Пример #2
0
            public void Sending_packet_with_byte_array_should_call_raw_client_with_header_appended()
            {
                var c = new FramedClient(rawClient.Object);

                c.SendPacket(new byte[] { 1, 2, 3 });

                rawClient.Verify(r => r.Send(new byte[] { 7, 0, 0, 0, 1, 2, 3 }));
            }
Пример #3
0
            public void Sending_preformatted_packet_should_not_add_additional_header()
            {
                var c    = new FramedClient(rawClient.Object);
                var data = new byte[] { 1, 2, 3, 4, 5, 6, 7 };

                var buffer = c.PreparePacketBuffer(7);

                Buffer.BlockCopy(data, 0, buffer.Packet.Array, buffer.Packet.Offset, data.Length);

                c.SendPacket(buffer);

                rawClient.Verify(r => r.Send(new byte[] { 11, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7 }));
                Assert.Equal(11, buffer.Packet.Array.Length);
                Assert.Equal(7, buffer.Packet.Count);
            }
Пример #4
0
        private unsafe void AuxSendProtocolPacket <P>(FramedClient client, int packetId, P packet)
        {
            using (var ms = new MemoryStream())
            {
                ms.SetLength(8);
                ms.Position = 8;
                serializer.Serialize(packet, ms);
                ms.Position = 0;

                var buffer = ms.GetBuffer();

                fixed(byte *buf = buffer)
                {
                    *(ActorProtocolFlags *)buf = ActorProtocolFlags.StacksProtocol;
                    *(int *)(buf + 4)          = packetId;
                }

                client.SendPacket(new ArraySegment <byte>(buffer, 0, (int)ms.Length));
            }
        }
Пример #5
0
        private unsafe void Send <R>(FramedClient client, long requestId, IReplyMessage <R> packet)
        {
            using (var ms = new MemoryStream())
            {
                ms.SetLength(12);
                ms.Position = 12;
                serializer.Serialize(packet, ms);
                ms.Position = 0;

                var buffer = ms.GetBuffer();

                fixed(byte *buf = buffer)
                {
                    *(ActorProtocolFlags *)buf = ActorProtocolFlags.RequestReponse;
                    *(long *)(buf + 4)         = requestId;
                }

                client.SendPacket(new ArraySegment <byte>(buffer, 0, (int)ms.Length));
            }
        }