Both encoder and decoder versions were functionally equivalent, but I picked the decoder version (but added the static inline keywords to it) since the encoder one was quite messy with a lot of commented out code.