private EntityData.Entity serializeEntityDelta(EntityRef entityRef, Prefab prefab) {
    EntityData.Entity.Builder entity = EntityData.Entity.newBuilder();
    entity.setId(entityRef.getId());
    entity.setParentPrefab(prefab.getName());
    for (Component component : entityRef.iterateComponents()) {
      if (component.getClass().equals(EntityInfoComponent.class)) continue;

      Component prefabComponent = prefab.getComponent(component.getClass());
      EntityData.Component componentData;
      if (prefabComponent == null) {
        componentData = serializeComponent(component);
      } else {
        componentData = serializeComponent(prefabComponent, component);
      }

      if (componentData != null) {
        entity.addComponent(componentData);
      }
    }
    for (Component prefabComponent : prefab.listComponents()) {
      if (!entityRef.hasComponent(prefabComponent.getClass())) {
        entity.addRemovedComponent(ComponentUtil.getComponentClassName(prefabComponent.getClass()));
      }
    }
    return entity.build();
  }
  @Override
  public Prefab deserializePrefab(EntityData.Prefab prefabData, String packageContext) {
    String name = prefabData.getName();
    if (!prefabData.getName().startsWith(packageContext + ":")) {
      int existingPackageName = name.lastIndexOf(':');
      if (existingPackageName != -1) {
        name = name.substring(existingPackageName + 1);
      }
      name = packageContext + ":" + name;
    }

    Prefab prefab = prefabManager.createPrefab(name);
    for (String parentName : prefabData.getParentNameList()) {
      int packageSplit = parentName.indexOf(':');
      if (packageSplit == -1) {
        parentName = packageContext + ":" + parentName;
      }
      Prefab parent = prefabManager.getPrefab(parentName);

      if (parent == null) {
        logger.log(Level.SEVERE, "Missing parent prefab (need to fix parent serialization)");
      } else {
        prefab.addParent(parent);
      }
    }

    for (EntityData.Component componentData : prefabData.getComponentList()) {
      Component component = deserializeComponent(componentData);
      if (component != null) {
        prefab.setComponent(component);
      }
    }

    return prefab;
  }
  @Override
  public EntityRef deserializeEntity(EntityData.Entity entityData) {
    EntityRef entity = entityManager.createEntityRefWithId(entityData.getId());
    if (entityData.hasParentPrefab()
        && !entityData.getParentPrefab().isEmpty()
        && prefabManager.exists(entityData.getParentPrefab())) {
      Prefab prefab = prefabManager.getPrefab(entityData.getParentPrefab());
      for (Component component : prefab.listComponents()) {
        String componentName = ComponentUtil.getComponentClassName(component.getClass());
        if (!containsIgnoreCase(componentName, entityData.getRemovedComponentList())) {
          entity.addComponent(componentLibrary.copy(component));
        }
      }
      entity.addComponent(new EntityInfoComponent(entityData.getParentPrefab()));
    }
    for (EntityData.Component componentData : entityData.getComponentList()) {
      Class<? extends Component> componentClass = getComponentClass(componentData);
      if (componentClass == null) continue;

      if (!entity.hasComponent(componentClass)) {
        entity.addComponent(deserializeComponent(componentData));
      } else {
        deserializeComponentOnto(entity.getComponent(componentClass), componentData);
      }
    }
    return entity;
  }
  @Override
  public EntityData.Prefab serializePrefab(Prefab prefab) {
    EntityData.Prefab.Builder prefabData = EntityData.Prefab.newBuilder();
    prefabData.setName(prefab.getName());
    for (Prefab parent : prefab.getParents()) {
      prefabData.addParentName(parent.getName());
    }

    for (Component component : prefab.listOwnComponents()) {
      EntityData.Component componentData = serializeComponent(component);
      if (componentData != null) {
        prefabData.addComponent(componentData);
      }
    }
    return prefabData.build();
  }
 @Override
 public Prefab deserializePrefab(EntityData.Prefab prefabData) {
   Prefab prefab = prefabManager.createPrefab(prefabData.getName());
   for (String parentName : prefabData.getParentNameList()) {
     Prefab parent = prefabManager.getPrefab(parentName);
     if (parent == null) {
       logger.log(Level.SEVERE, "Missing parent prefab (need to fix parent serialization)");
     } else {
       prefab.addParent(parent);
     }
   }
   for (EntityData.Component componentData : prefabData.getComponentList()) {
     Component component = deserializeComponent(componentData);
     if (component != null) {
       prefab.setComponent(component);
     }
   }
   return prefab;
 }