Exemplo n.º 1
0
        public void PayloadSplit()
        {
            var parts = new[]
            {
                new byte[UdpPayloadCache.UdpPayloadLength - 200],
                new byte[200],
                new byte[UdpPayloadCache.UdpPayloadLength - 400],
                new byte[200],
                new byte[400],
                new byte[UdpPayloadCache.UdpPayloadLength]
            };

            for (int i = 0; i < parts.Length - 1; i++)
            {
                parts[i].Populate((byte)(i + 1));
            }

            using (var cache = new UdpPayloadCache())
            {
                foreach (var part in parts)
                {
                    cache.Write(part, 0, part.Length);
                }

                var result = cache.GetPayloads();

                Assert.AreEqual(result.Length, 3);
                Assert.IsTrue(result[0].ContainsSubArray(parts[0]) && result[0].ContainsSubArray(parts[1]), "First split is wrong");
                Assert.IsTrue(result[1].ContainsSubArray(parts[2]) && result[1].ContainsSubArray(parts[3]) && !result[1].ContainsSubArray(parts[4]), "Second split is wrong");
                Assert.IsTrue(result[2].ContainsSubArray(parts[4]), "Third split is wrong");
                Assert.AreEqual(3, result.Length, "Amount of packets is not correct");
            }
        }
Exemplo n.º 2
0
        private void OnlySaveResult(ArraySegment <byte> smgt, UdpPayloadCache outStream)
        {
            if (smgt.Array == null)
            {
                return;
            }

            outStream.Write(smgt.Array, smgt.Offset, smgt.Count);
        }
Exemplo n.º 3
0
 private void SaveResult(byte[] input, UdpPayloadCache outStream)
 {
     outStream.Write(input, 0, input.Length);
 }