Add {de,}serialization functions and tests

TDD is the best
Better internal API and more tests