Moved and renamed encode/decode utility functions.