예제 #1
0
        public static object[] GetDynamicValues(Message msg, ParameterInfo[] parms)
        {
            //TODO: this validation check should provide better information, eg. message dump or a stack trace, or at least the interface/member

            /*
             * if (Protocol.Verbose) {
             *      Signature expected = Signature.GetSig (types);
             *      Signature actual = msg.Signature;
             *      if (actual != expected)
             *              Console.Error.WriteLine ("Warning: The signature of the message does not match that of the handler: " + "Expected '" + expected + "', got '" + actual + "'");
             * }
             */

            object[] vals = new object[parms.Length];

            if (msg.Body != null)
            {
                MessageReader reader = new MessageReader(msg);
                foreach (ParameterInfo parm in parms)
                {
                    if (parm.IsOut)
                    {
                        continue;
                    }

                    vals[parm.Position] = reader.ReadValue(parm.ParameterType);
                }
            }

            return(vals);
        }
예제 #2
0
        public static object[] GetDynamicValues(Message msg, Type[] types)
        {
            //TODO: this validation check should provide better information, eg. message dump or a stack trace, or at least the interface/member
            if (Protocol.Verbose)
            {
                Signature expected = Signature.GetSig(types);
                Signature actual   = msg.Signature;
                if (actual != expected)
                {
                    Console.Error.WriteLine("Warning: The signature of the message does not match that of the handler: " + "Expected '" + expected + "', got '" + actual + "'");
                }
            }

            object[] vals = new object[types.Length];

            if (msg.Body != null)
            {
                MessageReader reader = new MessageReader(msg);

                for (int i = 0; i != types.Length; i++)
                {
                    vals[i] = reader.ReadValue(types[i]);
                }
            }

            return(vals);
        }
예제 #3
0
        public object ToType(Type conversionType, IFormatProvider provider)
        {
            Signature typeSig = Signature.GetSig(conversionType);

            if (typeSig != signature)
            {
                throw new InvalidCastException(String.Format("{0} doesn't match {1}", typeSig.ToString(), signature.ToString()));
            }

            MessageReader reader = new MessageReader(endianness, data);

            return(reader.ReadValue(conversionType));
        }
예제 #4
0
		public static object[] GetDynamicValues (Message msg, Type[] types)
		{
			//TODO: this validation check should provide better information, eg. message dump or a stack trace, or at least the interface/member
			if (Protocol.Verbose) {
				Signature expected = Signature.GetSig (types);
				Signature actual = msg.Signature;
				if (actual != expected)
					Console.Error.WriteLine ("Warning: The signature of the message does not match that of the handler: " + "Expected '" + expected + "', got '" + actual + "'");
			}

			object[] vals = new object[types.Length];

			if (msg.Body != null) {
				MessageReader reader = new MessageReader (msg);

				for (int i = 0 ; i != types.Length ; i++)
					vals[i] = reader.ReadValue (types[i]);
			}

			return vals;
		}
예제 #5
0
		public static object[] GetDynamicValues (Message msg, ParameterInfo[] parms)
		{
			//TODO: this validation check should provide better information, eg. message dump or a stack trace, or at least the interface/member
			/*
			if (Protocol.Verbose) {
				Signature expected = Signature.GetSig (types);
				Signature actual = msg.Signature;
				if (actual != expected)
					Console.Error.WriteLine ("Warning: The signature of the message does not match that of the handler: " + "Expected '" + expected + "', got '" + actual + "'");
			}
			*/

			object[] vals = new object[parms.Length];

			if (msg.Body != null) {
				MessageReader reader = new MessageReader (msg);
				foreach (ParameterInfo parm in parms) {
					if (parm.IsOut)
						continue;

					vals[parm.Position] = reader.ReadValue (parm.ParameterType);
				}
			}

			return vals;
		}
예제 #6
0
        public static void Test(HashSet <ArgMatchTest> a, Message msg)
        {
            List <Signature> sigs = new List <Signature> ();

            sigs.AddRange(msg.Signature.GetParts());

            if (sigs.Count == 0)
            {
                a.Clear();
                return;
            }

            a.RemoveWhere(delegate(ArgMatchTest t) { return(t.ArgNum >= sigs.Count || t.Signature != sigs[t.ArgNum]); });

            // Sorting the list here is not ideal
            List <ArgMatchTest> tests = new List <ArgMatchTest> (a);

            tests.Sort(delegate(ArgMatchTest aa, ArgMatchTest bb) { return(aa.ArgNum - bb.ArgNum); });

            if (tests.Count == 0)
            {
                a.Clear();
                return;
            }

            MessageReader reader = new MessageReader(msg);

            int argNum = 0;

            foreach (ArgMatchTest test in tests)
            {
                if (argNum > test.ArgNum)
                {
                    // This test cannot pass because a previous test already did.
                    // So we already know it will fail without even trying.
                    // This logic will need to be changed to support wildcards.
                    a.Remove(test);
                    continue;
                }

                while (argNum != test.ArgNum)
                {
                    Signature sig = sigs[argNum];
                    if (!reader.StepOver(sig))
                    {
                        throw new Exception();
                    }
                    argNum++;
                }

                // TODO: Avoid re-reading values
                int savedPos = reader.pos;
                if (!reader.ReadValue(test.Signature[0]).Equals(test.Value))
                {
                    a.Remove(test);
                    reader.pos = savedPos;
                    continue;
                }

                argNum++;
            }
        }
        public static void Test(HashSet<ArgMatchTest> a, Message msg)
        {
            List<Signature> sigs = new List<Signature> ();
            sigs.AddRange (msg.Signature.GetParts ());

            if (sigs.Count == 0) {
                a.Clear ();
                return;
            }

            a.RemoveWhere ( delegate (ArgMatchTest t) { return t.ArgNum >= sigs.Count || t.Signature != sigs[t.ArgNum]; } );

            // Sorting the list here is not ideal
            List<ArgMatchTest> tests = new List<ArgMatchTest> (a);
            tests.Sort ( delegate (ArgMatchTest aa, ArgMatchTest bb) { return aa.ArgNum - bb.ArgNum; } );

            if (tests.Count == 0) {
                a.Clear ();
                return;
            }

            MessageReader reader = new MessageReader (msg);

            int argNum = 0;
            foreach (ArgMatchTest test in tests) {
                if (argNum > test.ArgNum) {
                    // This test cannot pass because a previous test already did.
                    // So we already know it will fail without even trying.
                    // This logic will need to be changed to support wildcards.
                    a.Remove (test);
                    continue;
                }

                while (argNum != test.ArgNum) {
                    Signature sig = sigs[argNum];
                    if (!reader.StepOver (sig))
                        throw new Exception ();
                    argNum++;
                }

                // TODO: Avoid re-reading values
                int savedPos = reader.pos;
                if (!reader.ReadValue (test.Signature[0]).Equals (test.Value)) {
                    a.Remove (test);
                    reader.pos = savedPos;
                    continue;
                }

                argNum++;
            }
        }
예제 #8
0
        public object ToType(Type conversionType, IFormatProvider provider)
        {
            Signature typeSig = Signature.GetSig (conversionType);
            if (typeSig != signature)
                throw new InvalidCastException ();

            MessageReader reader = new MessageReader (endianness, data);
            return reader.ReadValue (conversionType);
        }
예제 #9
0
파일: Monitor.cs 프로젝트: wuyinggz/tools
    internal static void PrintMessage(Message msg)
    {
        Console.WriteLine ("Message (" + msg.Header.Endianness + " endian, v" + msg.Header.MajorVersion + "):");
        Console.WriteLine (indent + "Type: " + msg.Header.MessageType);
        Console.WriteLine (indent + "Flags: " + msg.Header.Flags);
        Console.WriteLine (indent + "Serial: " + msg.Header.Serial);

        //foreach (HeaderField hf in msg.HeaderFields)
        //	Console.WriteLine (indent + hf.Code + ": " + hf.Value);
        Console.WriteLine (indent + "Header Fields:");
        foreach (KeyValuePair<FieldCode,object> field in msg.Header.Fields)
            Console.WriteLine (indent + indent + field.Key + ": " + field.Value);

        Console.WriteLine (indent + "Body (" + msg.Header.Length + " bytes):");
        if (msg.Body != null) {
            MessageReader reader = new MessageReader (msg);

            //TODO: this needs to be done more intelligently
            //TODO: number the args
            try {
                foreach (DType dtype in msg.Signature.GetBuffer ()) {
                    if (dtype == DType.Invalid)
                        continue;
                    object arg = reader.ReadValue (dtype);
                    Console.WriteLine (indent + indent + dtype + ": " + arg);
                }
            } catch {
                Console.WriteLine (indent + indent + "monitor is too dumb to decode message body");
            }
        }
    }