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

JSONRPC: Is it really that inconvenient? #1626

Open
receiver1 opened this issue Feb 19, 2025 · 1 comment
Open

JSONRPC: Is it really that inconvenient? #1626

receiver1 opened this issue Feb 19, 2025 · 1 comment

Comments

@receiver1
Copy link

receiver1 commented Feb 19, 2025

Hey! I'm trying to use JSONRPC and I don't understand why it doesn't have a tuple unpacking template. I end up having to write all the rpc methods by hand, but I want to use std::tuple or glz::tuple and loop through all the rpc methods for client::get_request_map when sending a request. Among other things, I tried to find documentation on glz::tuple, because I thought that this was provided there, but I couldn’t get to it. Either this is an incredibly awkward interface or it's incredibly poorly documented. The example contains almost nothing.

Here's what I did to achieve this:

using methods_t = std::tuple<
  methods::first_method, 
  methods::second_method
>;

template <typename Tuple, typename Indices =
              std::make_index_sequence<std::tuple_size<Tuple>::value>>
struct rpc_client_t;

template <typename... Methods, size_t... I>
struct rpc_client_t<std::tuple<Methods...>, std::index_sequence<I...>> {
  using type = rpc::client<std::tuple_element_t<I, std::tuple<Methods...>>...>;
};

I would like to know how this can be done more simply, if it is provided in principle, and how to correctly go through all the rpc methods to send a request?

@receiver1 receiver1 changed the title JsonRPC question JSONRPC: Is it really that inconvenient? Feb 19, 2025
@stephenberry
Copy link
Owner

I would probably be able to give you a more precise answer if I understood a bit more concretely what you're trying to do. You could try fleshing out an example.

But, take a look at how Glaze uses glz::for_each, which takes a lambda that provides a compile time known index I that you can use to access each member of a tuple. This would probably make your life much easier.

Feel free to submit pull requests if you discover ways to make this code easier to work with. Thanks for the feedback!

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

2 participants