Generate serialisation encoders for types.

Note done yet for functions etc.