Пример #1
0
        private byte[] Callback2(string names, byte[] paramsStr)
        {
            var param = RemoteProcedureCall.UnpackRpcValues(paramsStr, NtType.Boolean, NtType.BooleanArray, NtType.Double, NtType.DoubleArray, NtType.Raw, NtType.String, NtType.StringArray);

            if (param.Count == 0)
            {
                Console.Error.WriteLine("Empty Params?");
                return(new byte[] { 0 });
            }

            return(RemoteProcedureCall.PackRpcValues(RpcValue.MakeBoolean(true), RpcValue.MakeBooleanArray(new[] { true, false }), RpcValue.MakeDouble(2.2), RpcValue.MakeDoubleArray(new[] { 2.8, 6.876 }),
                                                     RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 }), RpcValue.MakeString("NewString"), RpcValue.MakeStringArray(new[] { "String1", "String2" })));
        }
Пример #2
0
        public void TestReadBooleanArray()
        {
            byte[]      b = { 0x03, 0x00, 0x01, 0x00, 0x02, 0x01, 0x00, 0xff };
            WireDecoder d = new WireDecoder(b);

            var val = d.ReadValue(NtType.BooleanArray);

            Assert.That(val.Type, Is.EqualTo(NtType.BooleanArray));
            Assert.That(val.Value, Is.EqualTo(v_boolArray.Value));

            var boolArray2 = RpcValue.MakeBooleanArray(true, false);

            val = d.ReadValue(NtType.BooleanArray);
            Assert.That(val.Type, Is.EqualTo(NtType.BooleanArray));
            Assert.That(val.Value, Is.EqualTo(boolArray2.Value));

            Assert.That(d.ReadValue(NtType.BooleanArray), Is.Null);
            Assert.That(d.Error, Is.Null);
        }
Пример #3
0
        public void TestRpcAllTypes()
        {
            CoreMethods.SetLogger((level, file, line, message) =>
            {
                //Console.Error.WriteLine(message);
            }, 0);

            var def = new NtRpcDefinition(1, "myfunc1", new[]
            {
                new NtRpcParamDef("param1", RpcValue.MakeBoolean(true)),
                new NtRpcParamDef("param2", RpcValue.MakeBooleanArray(new[] { true, false })),
                new NtRpcParamDef("param3", RpcValue.MakeDouble(0.0)),
                new NtRpcParamDef("param4", RpcValue.MakeDoubleArray(new[] { 2.8, 6.87 })),
                new NtRpcParamDef("param5", RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 })),
                new NtRpcParamDef("param6", RpcValue.MakeString("NewString")),
                new NtRpcParamDef("param7", RpcValue.MakeStringArray(new[] { "String1", "String2" })),
            }, new[]
            {
                new NtRpcResultDef("result1", NtType.Boolean),
                new NtRpcResultDef("result2", NtType.BooleanArray),
                new NtRpcResultDef("result3", NtType.Double),
                new NtRpcResultDef("result4", NtType.DoubleArray),
                new NtRpcResultDef("result5", NtType.Raw),
                new NtRpcResultDef("result6", NtType.String),
                new NtRpcResultDef("result7", NtType.StringArray),
            });

            RemoteProcedureCall.CreateRpc("func1", def, Callback2);

            Console.WriteLine("Calling RPC");

            uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeBoolean(true), RpcValue.MakeBooleanArray(new[] { true, false }), RpcValue.MakeDouble(2.2), RpcValue.MakeDoubleArray(new[] { 2.8, 6.87 }),
                                                        RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 }), RpcValue.MakeString("NewString"), RpcValue.MakeStringArray(new[] { "String1", "String2" }));

            Console.WriteLine("Waiting for RPC Result");
            byte[] result      = RemoteProcedureCall.GetRpcResult(true, call1Uid);
            var    call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Boolean, NtType.BooleanArray, NtType.Double, NtType.DoubleArray, NtType.Raw, NtType.String, NtType.StringArray);

            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }
Пример #4
0
        public RpcValue ReadValue(NtType type)
        {
            byte size = 0;

            byte[] buf;
            Error = null;
            switch (type)
            {
            case NtType.Boolean:
                byte vB = 0;
                return(!Read8(ref vB) ? null : RpcValue.MakeBoolean(vB != 0));

            case NtType.Double:
                double vD = 0;
                return(!ReadDouble(ref vD) ? null : RpcValue.MakeDouble(vD));

            case NtType.Raw:
                byte[] vRa = null;
                return(!ReadRaw(ref vRa) ? null : RpcValue.MakeRaw(vRa));

            case NtType.Rpc:
            case NtType.String:
                string vS = "";
                return(!ReadString(ref vS) ? null : RpcValue.MakeString(vS));

            case NtType.BooleanArray:
                if (!Read8(ref size))
                {
                    return(null);
                }
                buf = ReadArray(size);
                if (buf == null)
                {
                    return(null);
                }
                bool[] bBuf = new bool[buf.Length];
                for (int i = 0; i < buf.Length; i++)
                {
                    bBuf[i] = buf[i] != 0;
                }
                return(RpcValue.MakeBooleanArray(bBuf));

            case NtType.DoubleArray:
                if (!Read8(ref size))
                {
                    return(null);
                }
                buf = ReadArray(size * 8);
                if (buf == null)
                {
                    return(null);
                }
                double[] dBuf = new double[size];
                for (int i = 0; i < size; i++)
                {
                    dBuf[i] = ReadDouble(buf, i * 8);
                }
                return(RpcValue.MakeDoubleArray(dBuf));

            case NtType.StringArray:
                if (!Read8(ref size))
                {
                    return(null);
                }
                string[] sBuf = new string[size];
                for (int i = 0; i < size; i++)
                {
                    if (!ReadString(ref sBuf[i]))
                    {
                        return(null);
                    }
                }
                return(RpcValue.MakeStringArray(sBuf));

            default:
                Error = "invalid type when trying to read value";
                Console.WriteLine("invalid type when trying to read value");
                return(null);
            }
        }