public RpcRequest DeserializeRequest(byte[] body, RpcSignatureResolver resolver)
        {
            using (MemoryStream ms = new MemoryStream(body)) {
                // deserialize response message
                RequestMsg msg = Serializer.Deserialize <RequestMsg>(ms);

                // convert arguments
                Dictionary <string, object> args      = new Dictionary <string, object>();
                Dictionary <string, Type>   argsTypes = new Dictionary <string, Type>();
                RpcArgument[] rpcArgs = resolver(msg.Interface, msg.Operation);

                if (msg.Arguments != null)
                {
                    foreach (ValueMsg arg in msg.Arguments)
                    {
                        if (arg.Key == null)
                        {
                            continue;
                        }

                        // add argument
                        RpcArgument rpcArg = rpcArgs.Single(a => a.Name.Equals(arg.Key, StringComparison.CurrentCultureIgnoreCase));

                        args.Add(arg.Key, arg.GetData(rpcArg.Type));
                        argsTypes.Add(arg.Key, rpcArg.Type);
                    }
                }

                return(new RpcRequest(msg.Interface, msg.Operation, args, argsTypes));
            }
        }
        public RpcRequest DeserializeRequest(byte[] body, RpcSignatureResolver resolver)
        {
            using (MemoryStream ms = new MemoryStream(body)) {
                XDocument doc = XDocument.Load(ms);

                // read request
                XElement req = doc.Elements().First();

                if (req.Name != "Request")
                {
                    throw new InvalidDataException("Invalid XML document for RPC");
                }

                XAttribute iface = req.Attribute(XName.Get("i"));
                XAttribute op    = req.Attribute(XName.Get("o"));

                // read arguments
                XElement arguments = req.Elements().SingleOrDefault((e) => e.Name == "Arguments");
                Dictionary <string, object> argumentsData = new Dictionary <string, object>();
                Dictionary <string, Type>   argumentTypes = new Dictionary <string, Type>();

                if (arguments != null)
                {
                    // resolve arguments
                    RpcArgument[] args = resolver(iface.Value, op.Value);
                    Dictionary <string, RpcArgument> argsMap = new Dictionary <string, RpcArgument>();

                    foreach (RpcArgument arg in args)
                    {
                        argsMap[arg.Name] = arg;
                    }

                    // look for matching elements
                    foreach (XElement argElement in arguments.Elements())
                    {
                        string argVal = argElement.Value;

                        if (argsMap.TryGetValue(argElement.Name.LocalName, out RpcArgument arg))
                        {
                            argumentsData[arg.Name] = DeserializeValue(arg.Type, argElement);
                            argumentTypes[arg.Name] = arg.Type;
                        }
                    }
                }

                return(new RpcRequest(iface.Value, op.Value, argumentsData, argumentTypes));
            }
        }
 public RpcRequest[] DeserializeRequestBatch(byte[] body, RpcSignatureResolver resolver)
 {
     throw new NotImplementedException();
 }