Always map NULL values to Qnil.

This removes duplicated code from type converters and will speedup converters implemented in ruby.
Detach type decoders from Result, so that they could be used with COPY.

Change type encoders to a two pass mechanism, which could also be used with COPY.