CNMAT/OSC

Help with pattern matching

Mark-81 opened this issue · 0 comments

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.