Move some serialization functions to their own file.