public byte[] SerializeResponse(RpcResponse response)
        {
            using (MemoryStream ms = new MemoryStream()) {
                // create response message
                ResponseMsg res = new ResponseMsg();
                res.IsSuccess = response.IsSuccess;

                if (response.IsSuccess)
                {
                    ValueMsg result = new ValueMsg();
                    result.SetData(response.Data, response.DataType);
                    res.Data = result;
                }
                else
                {
                    res.Error = new ErrorMsg()
                    {
                        Code    = response.Error.Code,
                        Message = response.Error.Message,
                        Details = response.Error.Details
                    };
                }

                Serializer.Serialize(ms, res);
                return(ms.ToArray());
            }
        }
Exemplo n.º 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());
            }
        }