Exemplo n.º 1
0
        private void FixAndSaveResult(ArraySegment <byte> smgt, UdpPayloadCache outStream)
        {
            UdpSentence baseModel = null;

            try
            {
                if (UdpPanSpt.TryParse(smgt, out var sptModel))
                {
                    FixPANSPT(sptModel);
                    baseModel = sptModel;
                }
                else if (UdpPanSsy.TryParse(smgt, out var ssyModel))
                {
                    FixPANSSY(ssyModel);
                    baseModel = ssyModel;
                }
                else
                {
                    OnlySaveResult(smgt, outStream);
                }

                if (baseModel != null)
                {
                    SaveResult(baseModel.ToBytes(), outStream);
                }
            }
            catch
            {
                // ignored
            }
        }
Exemplo n.º 2
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.º 3
0
        private void OnlySaveResult(ArraySegment <byte> smgt, UdpPayloadCache outStream)
        {
            if (smgt.Array == null)
            {
                return;
            }

            outStream.Write(smgt.Array, smgt.Offset, smgt.Count);
        }
Exemplo n.º 4
0
        private byte[][] FixSentences(byte[] input)
        {
            using (var outStream = new UdpPayloadCache())
            {
                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i] == UdpSentence.SentenceBegin)
                    {
                        var sntSgmt = GetSentenceFrom(input, i);

                        FixAndSaveResult(sntSgmt, outStream);

                        i += sntSgmt.Count - 1;
                    }
                    else
                    {
                        outStream.WriteByte(input[i]);
                    }
                }

                return(outStream.GetPayloads());
            }
        }
Exemplo n.º 5
0
 private void SaveResult(byte[] input, UdpPayloadCache outStream)
 {
     outStream.Write(input, 0, input.Length);
 }