io.tarantool.driver.core.metadata.VSpaceToTarantoolSpaceMetadataConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cartridge-driver Show documentation
Show all versions of cartridge-driver Show documentation
Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework
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