public void MessageShouldBeInQueueAfterReceive() { ackSystem.ReceiveReliable(packet1, packet1.Length, true); Assert.IsFalse(ackSystem.NextReliablePacket(out var _)); ackSystem.ReceiveReliable(packet2, packet2.Length, true); var bytesIn1 = MAX_PACKET_SIZE - AckSystem.MIN_RELIABLE_FRAGMENT_HEADER_SIZE; var bytesIn2 = message.Length - bytesIn1; Assert.IsTrue(ackSystem.NextReliablePacket(out var first)); Assert.IsTrue(first.IsFragment); Assert.That(first.Buffer.array[0], Is.EqualTo(1), "First fragment should have index 1"); Assert.That(first.Length, Is.EqualTo(bytesIn1 + 1)); AssertAreSameFromOffsets(message, 0, first.Buffer.array, 1, bytesIn1); var second = ackSystem.GetNextFragment(); Assert.IsTrue(second.IsFragment); Assert.That(second.Buffer.array[0], Is.EqualTo(0), "Second fragment should have index 0"); Assert.That(second.Length, Is.EqualTo(bytesIn2 + 1)); AssertAreSameFromOffsets(message, bytesIn1, second.Buffer.array, 1, bytesIn2); }
private static List <byte[]> Receive(AckSystem ackSystem, byte[] packet) { var messages = new List <byte[]>(); var type = (PacketType)packet[0]; switch (type) { case PacketType.Reliable: ackSystem.ReceiveReliable(packet, packet.Length, false); break; case PacketType.Ack: ackSystem.ReceiveAck(packet); break; case PacketType.Command: case PacketType.Unreliable: case PacketType.Notify: case PacketType.KeepAlive: default: break; } while (ackSystem.NextReliablePacket(out var received)) { HandleAllMessageInPacket(messages, received); } return(messages); }