Add support for encoding null values

The encoder silently fails when encoding null values. This pull requests adds support for encoding null values, and adds tests to make sure null values are correctly decoded and encoded.