A real implementation would probably be switch-driven, but I whipped up a terse implementation for a big-endian bijective encoder to go with my other comment (tested, but test code omitted):
7 bits -> Decode 0xxxxxxx and add 0 (unchanged)
14 bits -> Decode 10xxxxxx xxxxxxxx and add 0x80
21 bits -> Decode 110xxxxx xxxxxxxx xxxxxxxx and add 0x4080
In a non-bijective base vs a bijective base:
7 bits encode 0 to 2&7 - 1 vs. 0 to 2^7 -1
14 bits encode 0 to 2^14 - 1 vs. 2^7 to 2^14 + 2^7 - 1
21 bits encode 0 to 2^21 - 1 vs. 2^14 + 2^7 to 2^21 + 2^14 + 2^7 - 1
...
In the bijective decoding routine, you need to special-case the maximum length case to check for numeric overflow.