Add encoder.

Closes #9.