Examples of PersistedData


Examples of org.terasology.persistence.typeHandling.PersistedData

        NON_NULL
    }

    @Test
    public void testNullValue() throws Exception {
        PersistedData nullData = mock(PersistedData.class);
        when(nullData.isNull()).thenReturn(true);

        SerializationContext serializationContext = mock(SerializationContext.class);
        when(serializationContext.createNull()).thenReturn(nullData);
        EnumTypeHandler<TestEnum> handler = new EnumTypeHandler<>(TestEnum.class);
        PersistedData serializedNull = handler.serialize(null, serializationContext);
        assertEquals(nullData, serializedNull);

        DeserializationContext deserializationContext = mock(DeserializationContext.class);
        TestEnum deserializedValue = handler.deserialize(nullData, deserializationContext);
        assertEquals(null, deserializedValue);
View Full Code Here

Examples of org.terasology.persistence.typeHandling.PersistedData

        assertEquals(null, deserializedValue);
    }

    @Test
    public void testNonNullValue() throws Exception {
        PersistedData data = mock(PersistedData.class);
        when(data.getAsString()).thenReturn(TestEnum.NON_NULL.toString());
        when(data.isString()).thenReturn(true);

        SerializationContext serializationContext = mock(SerializationContext.class);
        when(serializationContext.create(TestEnum.NON_NULL.toString())).thenReturn(data);
        EnumTypeHandler<TestEnum> handler = new EnumTypeHandler<>(TestEnum.class);
        PersistedData serializedNonNull = handler.serialize(TestEnum.NON_NULL, serializationContext);
        assertEquals(data, serializedNonNull);

        DeserializationContext deserializationContext = mock(DeserializationContext.class);
        TestEnum deserializedValue = handler.deserialize(data, deserializationContext);
        assertEquals(TestEnum.NON_NULL, deserializedValue);
View Full Code Here

Examples of org.terasology.persistence.typeHandling.PersistedData

        Map<String, PersistedData> mappedData = Maps.newLinkedHashMap();
        for (Map.Entry<FieldMetadata<T, ?>, TypeHandler<?>> entry : mappedFields.entrySet()) {
            Object val = entry.getKey().getValue(value);
            if (val != null) {
                TypeHandler handler = entry.getValue();
                PersistedData fieldValue = handler.serialize(val, context);
                if (fieldValue != null) {
                    mappedData.put(entry.getKey().getName(), fieldValue);
                }
            }
        }
View Full Code Here

Examples of org.terasology.persistence.typeHandling.PersistedData

    @Override
    public PersistedData serialize(Map<String, T> value, SerializationContext context) {
        Map<String, PersistedData> map = Maps.newLinkedHashMap();
        for (Map.Entry<String, T> entry : value.entrySet()) {
            PersistedData item = contentsHandler.serialize(entry.getValue(), context);
            if (!item.isNull()) {
                map.put(entry.getKey(), item);
            }
        }
        return context.create(map);
    }
View Full Code Here

Examples of org.terasology.persistence.typeHandling.PersistedData

        serializeComponentType(componentMetadata, componentMessage);

        Serializer serializer = typeSerializationLibrary.getSerializerFor(componentMetadata);
        for (ReplicatedFieldMetadata field : componentMetadata.getFields()) {
            if (check.shouldSerializeField(field, component)) {
                PersistedData result = serializer.serialize(field, component, serializationContext);
                if (!result.isNull()) {
                    EntityData.Value itemValue = ((ProtobufPersistedData) result).getValue();
                    if (usingFieldIds) {
                        componentMessage.addField(EntityData.NameValue.newBuilder().setNameIndex(field.getId()).setValue(itemValue));
                    } else {
                        componentMessage.addField(EntityData.NameValue.newBuilder().setName(field.getName()).setValue(itemValue));
View Full Code Here

Examples of org.terasology.persistence.typeHandling.PersistedData

            if (check.shouldSerializeField(field, delta)) {
                Object origValue = field.getValue(base);
                Object deltaValue = field.getValue(delta);

                if (!Objects.equal(origValue, deltaValue)) {
                    PersistedData value = serializer.serializeValue(field, deltaValue, serializationContext);
                    if (!value.isNull()) {
                        EntityData.Value dataValue = ((ProtobufPersistedData) value).getValue();
                        if (usingFieldIds) {
                            componentMessage.addField(EntityData.NameValue.newBuilder().setNameIndex(field.getId()).setValue(dataValue).build());
                        } else {
                            componentMessage.addField(EntityData.NameValue.newBuilder().setName(field.getName()).setValue(dataValue).build());
View Full Code Here

Examples of org.terasology.persistence.typeHandling.PersistedData

        for (ReplicatedFieldMetadata field : componentMetadata.getFields()) {
            if (fieldCheck.shouldSerializeField(field, newComponent, componentInitial)) {
                Object oldValue = field.getValue(oldComponent);
                Object newValue = field.getValue(newComponent);
                if (!Objects.equal(oldValue, newValue)) {
                    PersistedData data = serializer.serializeValue(field, newValue, serializationContext);
                    if (!data.isNull()) {
                        entityFieldIds.write(field.getId());
                        entityData.addFieldValue(((ProtobufPersistedData) data).getValue());
                        fieldCount++;
                    } else {
                        logger.error("Exception serializing component type: {}, field: {} - returned null", componentMetadata, field);
View Full Code Here

Examples of org.terasology.persistence.typeHandling.PersistedData

        Serializer serializer = typeSerializationLibrary.getSerializerFor(componentMetadata);
        byte fieldCount = 0;
        for (ReplicatedFieldMetadata field : componentMetadata.getFields()) {
            if (fieldCheck.shouldSerializeField(field, component, componentInitial)) {
                PersistedData fieldValue = serializer.serialize(field, component, serializationContext);
                entityFieldIds.write(field.getId());

                entityData.addFieldValue(((ProtobufPersistedData) fieldValue).getValue());
                fieldCount++;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.