Added reverse mapping for message classes and ids

Before, the method was doing an O(n) lookup on the keys of the hash, while it's
possible to simply do an #invert on the hash, then we can use the hashed
key-pair values.