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

Help with pattern matching #109

Open
ghost opened this issue Jan 15, 2020 · 0 comments
Open

Help with pattern matching #109

ghost opened this issue Jan 15, 2020 · 0 comments
Assignees

Comments

@ghost
Copy link

ghost commented Jan 15, 2020

I've already read the documentation and the examples about pattern matching.
But I still have some difficulties to understand how should I approach a very simple scenario.

The incoming messages have the following addresses:

/<group>/<command>/<index>

or

/<command>/<index>

examples:

/servo/set/1
/servo/move/2
/set/1
...

So the same <command> items may be present with or without the <group>.
I want to (partially) match until the <index> item, but starting from the root.

I did something like this:

  msg.route("/servo/move", servo_move_handler);
  msg.route("/servo/set", servo_set_handler);
  msg.route("/set", set_handler);

Then I retrieve the <index> in this way:

int getIndex(OSCMessage &msg, int patternOffset)
{
  char buf[8];
  msg.getAddress(buf, patternOffset + 1, 8);

  return atoi(buf);
}

Well, it seems it works correctly, but I want to be sure this is the correct way to approach such a situation.

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

1 participant