Esempio n. 1
0
        public void Deserialize <PARSER>(PARSER parser, ref RPCNotify <JsonParser> outValue) where PARSER : IParser <PARSER>
        {
            foreach (var kv in parser.ObjectItems)
            {
                switch (kv.Key)
                {
                case "jsonrpc":
                    if (kv.Value.GetString() != "2.0")
                    {
                        throw new FormatException("jsonrpc should 2.0");
                    }
                    break;

                case "method":
                    outValue.Method = kv.Value.GetString();
                    break;

                case "args":
                case "params":
                    outValue.ParamsBytes = kv.Value.Dump();
                    break;

                default:
                    throw new FormatException("unknown key: " + kv.Key);
                }
            }
        }
Esempio n. 2
0
        public void Deserialize <PARSER>(PARSER parser, ref RPCNotify <MessagePackParser> outValue) where PARSER : IParser <PARSER>
        {
            var it = parser.ListItems.GetEnumerator();

            it.MoveNext(); if (it.Current.GetInt32() != 2)
            {
                throw new FormatException("request should 0");
            }
            it.MoveNext(); outValue.Method      = it.Current.GetString();
            it.MoveNext(); outValue.ParamsBytes = it.Current.Dump();
        }
Esempio n. 3
0
        public void MsgPackRpcDispatchNotify()
        {
            // setup
            var typeRegistry = new TypeRegistry();
            var method       = typeRegistry.RPCFunc((int a, int b) => a + b);
            var dispatcher   = new RPCDispatcher();

            dispatcher.AddNotifyMethod("Add", method);

            // notify
            var notify = new RPCNotify <Osaru.MessagePack.MessagePackParser>
            {
                Method      = "Add",
                ParamsBytes = typeRegistry.SerializeToMessagePack(new[] { 1, 2 })
            };

            dispatcher.DispatchNotify(notify);
        }