CNMAT / OSC

OSC: Arduino and Teensy implementation of OSC encoding
cnmat.berkeley.edu/oscuino
Other
727 stars 135 forks source link

Help with pattern matching #109

Open ghost opened 4 years ago

ghost commented 4 years ago

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.