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));
            }
        }
Exemple #2
0
        public byte[] SerializeRequest(RpcRequest request)
        {
            using (MemoryStream ms = new MemoryStream()) {
                // create request message
                RequestMsg req = new RequestMsg();
                req.Interface = request.Interface;
                req.Operation = request.Operation;
                req.Arguments = request.Arguments.Select(kv => {
                    ValueMsg value = new ValueMsg()
                    {
                        Key = kv.Key
                    };
                    value.SetData(kv.Value);
                    return(value);
                }).ToArray();

                Serializer.Serialize(ms, req);
                return(ms.ToArray());
            }
        }