Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add optional parameters to the server method #32

Closed
nk1973 opened this issue Dec 17, 2013 · 3 comments
Closed

Cannot add optional parameters to the server method #32

nk1973 opened this issue Dec 17, 2013 · 3 comments

Comments

@nk1973
Copy link

nk1973 commented Dec 17, 2013

I see such limitation in the lib (may be i miss something).

  1. According to spec: http://www.jsonrpc.org/specification#request_object
    request params may be omitted.
  2. i want to implement method that take optional parameters, - that is the client can omit them in run time. For example method
    GetLog(optional filter1, optional filter2,...).
    So in one run the client can use GetLog(time filter)
    like this
    {"jsonrpc": "2.0", "method": "GetLog", "params": ["2013/12/00:00:00"], "id": 1}
    In the other without any filter (according to the spec this seems to be OK)
    {"jsonrpc": "2.0", "method": "GetLog", "id": 1}

But i don't see how i implement this with the lib (something like c++ overloading).

@toolmmy
Copy link

toolmmy commented Dec 17, 2013

You should be able to register a method that has an object as parameter (e.g. "params" : {"dateFrom": x, "dateTo":y}). In your callback, based in the provided data in the Json::Value& request you can figure out what you need to return. In this case your callback acts more like a facade.

@nk1973
Copy link
Author

nk1973 commented Dec 17, 2013

Yes this should work for the most of the cases (when params object exist). The only problem is if the client will omit params object - according to spec he may do it - and then the client will received exception.

I thinked about something like c++ overloading. Server can register multiple methods with the same name but with different parameter list.
Something like

class AbstarctMyStubServer ...
{
public:
AbstarctMyStubServer(...)
{
}

virtual Json::Value GetLog() = 0;
virtual Json::Value GetLog(const std::string &param1 ) = 0;
virtual Json::Value GetLog(const std::string &param1, const std::string &param1) = 0;
...
};

But the problem is that i don't see this is possible with current lib. (may be i'm wrong).

@cinemast
Copy link
Owner

The thing is, that this behavior is not specified in the standard proposal. If you need such things, fork this repo and adapt this as required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants