It's pretty simple, it just transforms all the data on the hero (unit type, level, attributes, items, abilities and so on...) to some code and then on -load transforms them back.
If you don't want to do it yourself, just try some of the systems someone already created, like
this one.