State machine serialization/deserialization