コード例 #1
0
        public void DeserializeRandomizedMessagesAndCompareRecursivelyToOriginals()
        {
            // randomize messages of all known types, and serialize one of each of them
            var messageTypes = MessageTypeRegistry.Default.GetTypeNames().ToList();

            foreach (var messageType in messageTypes)
            {
                var original = RosMessage.Generate(messageType);
                Assert.NotNull(original);
                original.Randomize();
                byte[] originalSerialized = null;
                try
                {
                    originalSerialized = original.Serialize();
                }
                catch (Exception e)
                {
                    int a = 1;
                }
                Assert.NotNull(originalSerialized);

                RosMessage msg = RosMessage.Generate(messageType);
                Assert.NotNull(msg);

                try
                {
                    msg.Deserialize(originalSerialized);
                }
                catch (Exception e)
                {
                    int a = 1;
                }
                Assert.Equal(original, msg);
            }
        }
コード例 #2
0
        public void CheckMsgMD5()
        {
            var msgSums      = msgSumsLazy.Value;
            var typeRegistry = MessageTypeRegistry.Default.TypeRegistry;

            foreach (var key in msgSums.Keys.Where(typeRegistry.ContainsKey))
            {
                var    msg        = RosMessage.Generate(key);
                string desiredSum = msgSums[key];
                string actualSum  = msg.MD5Sum();
                Assert.Equal(desiredSum, actualSum);
            }
        }
コード例 #3
0
ファイル: MD5.cs プロジェクト: wiwing/ROS.NET
        private static string PrepareToHash(MsgFile msgFile)
        {
            string hashText = msgFile.Definition.Trim('\n', '\t', '\r', ' ');

            while (hashText.Contains("  "))
            {
                hashText = hashText.Replace("  ", " ");
            }
            while (hashText.Contains("\r\n"))
            {
                hashText = hashText.Replace("\r\n", "\n");
            }
            hashText = hashText.Trim();
            string[] lines = hashText.Split('\n');

            var haves    = new Queue <string>();
            var havenots = new Queue <string>();

            for (int i = 0; i < lines.Length; i++)
            {
                string l = lines[i];
                if (l.Contains("="))
                {
                    // condense spaces on either side of =
                    string[] ls = l.Split('=');
                    haves.Enqueue(ls[0].Trim() + "=" + ls[1].Trim());
                }
                else
                {
                    havenots.Enqueue(l.Trim());
                }
            }

            hashText = "";
            while (haves.Count + havenots.Count > 0)
            {
                hashText += (haves.Count > 0 ? haves.Dequeue() : havenots.Dequeue()) + (haves.Count + havenots.Count >= 1 ? "\n" : "");
            }

            Dictionary <string, MsgFieldInfo> mfis = MessageFieldHelper.Instantiate(msgFile.Stuff);

            MsgFieldInfo[] fields = mfis.Values.ToArray();
            for (int i = 0; i < fields.Length; i++)
            {
                var field = fields[i];
                if (field.IsPrimitive)
                {
                    continue;
                }

                MsgFile ms = msgFile.Stuff[i].Definer;
                if (ms == null)
                {
                    KnownStuff.WhatItIs(msgFile, msgFile.Stuff[i]);
                    if (msgFile.Stuff[i].Type.Contains("/"))
                    {
                        msgFile.resolve(msgFile.Stuff[i]);
                    }
                    ms = msgFile.Stuff[i].Definer;
                }
                string sum = null;
                if (ms == null)
                {
                    RosMessage rosMessage = null;
                    var        packages   = MessageTypeRegistry.Default.PackageNames;
                    foreach (var package in packages)
                    {
                        try
                        {
                            var name = msgFile.Stuff[i].Type;
                            Console.WriteLine($"generate {package}/{name}");
                            rosMessage = RosMessage.Generate($"{package}/{name}");
                            sum        = rosMessage.MD5Sum();
                            break;
                        }
                        catch
                        {
                        }
                    }
                    if (rosMessage == null)
                    {
                        Logger.LogDebug("NEEDS ANOTHER PASS: "******" B/C OF " + msgFile.Stuff[i].Type);
                        return(null);
                    }
                }
                else
                {
                    sum = MD5.Sum(ms);
                }
                if (sum == null)
                {
                    Logger.LogDebug("STILL NEEDS ANOTHER PASS: "******" B/C OF " + msgFile.Stuff[i].Type);
                    return(null);
                }

                hashText = Regex.Replace(hashText, @"^(.*/)?\b" + fields[i].Type + @"\b(\s*\[\s*\])?", sum, RegexOptions.Multiline);
            }
            return(hashText);
        }