Search in sources :

Example 1 with ProtobufDeserializationContext

use of org.terasology.persistence.typeHandling.protobuf.ProtobufDeserializationContext in project Terasology by MovingBlocks.

the class ComponentSerializer method deserializeOnto.

private <T extends Component> Component deserializeOnto(Component targetComponent, EntityData.Component componentData, ComponentMetadata<T> componentMetadata, FieldSerializeCheck<Component> fieldCheck) {
    Serializer serializer = typeSerializationLibrary.getSerializerFor(componentMetadata);
    DeserializationContext context = new ProtobufDeserializationContext(typeSerializationLibrary);
    Map<FieldMetadata<?, ?>, PersistedData> dataMap = Maps.newHashMapWithExpectedSize(componentData.getFieldCount());
    for (EntityData.NameValue field : componentData.getFieldList()) {
        FieldMetadata<?, ?> fieldInfo = null;
        if (field.hasNameIndex()) {
            fieldInfo = componentMetadata.getField(field.getNameIndex());
        } else if (field.hasName()) {
            fieldInfo = componentMetadata.getField(field.getName());
        }
        if (fieldInfo != null) {
            dataMap.put(fieldInfo, new ProtobufPersistedData(field.getValue()));
        } else if (field.hasName()) {
            logger.warn("Cannot deserialize unknown field '{}' onto '{}'", field.getName(), componentMetadata.getUri());
        }
    }
    serializer.deserializeOnto(targetComponent, dataMap, context, fieldCheck);
    return targetComponent;
}
Also used : FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) ReplicatedFieldMetadata(org.terasology.entitySystem.metadata.ReplicatedFieldMetadata) ProtobufPersistedData(org.terasology.persistence.typeHandling.protobuf.ProtobufPersistedData) EntityData(org.terasology.protobuf.EntityData) DeserializationContext(org.terasology.persistence.typeHandling.DeserializationContext) ProtobufDeserializationContext(org.terasology.persistence.typeHandling.protobuf.ProtobufDeserializationContext) ProtobufDeserializationContext(org.terasology.persistence.typeHandling.protobuf.ProtobufDeserializationContext) PersistedData(org.terasology.persistence.typeHandling.PersistedData) ProtobufPersistedData(org.terasology.persistence.typeHandling.protobuf.ProtobufPersistedData) Serializer(org.terasology.persistence.typeHandling.Serializer)

Aggregations

ReplicatedFieldMetadata (org.terasology.entitySystem.metadata.ReplicatedFieldMetadata)1 DeserializationContext (org.terasology.persistence.typeHandling.DeserializationContext)1 PersistedData (org.terasology.persistence.typeHandling.PersistedData)1 Serializer (org.terasology.persistence.typeHandling.Serializer)1 ProtobufDeserializationContext (org.terasology.persistence.typeHandling.protobuf.ProtobufDeserializationContext)1 ProtobufPersistedData (org.terasology.persistence.typeHandling.protobuf.ProtobufPersistedData)1 EntityData (org.terasology.protobuf.EntityData)1 FieldMetadata (org.terasology.reflection.metadata.FieldMetadata)1