km: implement serialization.