All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.tarantool.driver.core.metadata.VSpaceToTarantoolSpaceMetadataConverter Maven / Gradle / Ivy

Go to download

Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework

There is a newer version: 0.14.0
Show newest version
package io.tarantool.driver.core.metadata;

import io.tarantool.driver.api.metadata.TarantoolSpaceMetadata;
import io.tarantool.driver.mappers.MessagePackMapper;
import io.tarantool.driver.mappers.converters.ValueConverter;
import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory;
import org.msgpack.value.ArrayValue;
import org.msgpack.value.Value;

import java.util.Iterator;

/**
 * Populates space metadata. Input is expected to have the _vspace format.
 * See
 * 
 * https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/_vspace/
 * 
 *
 * @author Alexey Kuzin
 * @author Artyom Dubinin
 */
public final class VSpaceToTarantoolSpaceMetadataConverter
    implements ValueConverter {

    private static final long serialVersionUID = 3251153816139308575L;

    private static final VSpaceToTarantoolSpaceMetadataConverter instance =
        new VSpaceToTarantoolSpaceMetadataConverter();

    private static final MessagePackMapper mapper =
        DefaultMessagePackMapperFactory.getInstance().defaultComplexTypesMapper();

    private static final ArrayValueToSpaceFormatConverter arrayValueToSpaceFormatConverter
        = ArrayValueToSpaceFormatConverter.getInstance();

    private VSpaceToTarantoolSpaceMetadataConverter() {
    }

    public TarantoolSpaceMetadata fromValue(ArrayValue space) {
        Iterator it = space.iterator();

        TarantoolSpaceMetadataImpl spaceMetadata = new TarantoolSpaceMetadataImpl();

        spaceMetadata.setSpaceId(mapper.fromValue(it.next().asIntegerValue()));
        spaceMetadata.setOwnerId(mapper.fromValue(it.next().asIntegerValue()));
        spaceMetadata.setSpaceName(mapper.fromValue(it.next().asStringValue()));

        Value spaceMetadataValue = it.next();
        while (!spaceMetadataValue.isArrayValue()) {
            spaceMetadataValue = it.next();
        }

        spaceMetadata.setSpaceFormatMetadata(
            arrayValueToSpaceFormatConverter.fromValue(
                spaceMetadataValue.asArrayValue()
            )
        );

        return spaceMetadata;
    }

    public static VSpaceToTarantoolSpaceMetadataConverter getInstance() {
        return instance;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy