Add some useful encode/decode functions.