Free function serialize replaces to_stream