36 lines
1.3 KiB
Java
36 lines
1.3 KiB
Java
package it.cavallium.dbengine.database.collections;
|
|
|
|
import io.net5.buffer.api.Buffer;
|
|
import io.net5.buffer.api.Resource;
|
|
import io.net5.buffer.api.Send;
|
|
import it.cavallium.dbengine.client.CompositeSnapshot;
|
|
import it.cavallium.dbengine.database.LLDictionary;
|
|
import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing;
|
|
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
|
import java.util.Map;
|
|
import org.jetbrains.annotations.Nullable;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
public class SubStageGetterSet<T> implements SubStageGetter<Map<T, Nothing>, DatabaseSetDictionary<T>> {
|
|
|
|
private final SerializerFixedBinaryLength<T> keySerializer;
|
|
|
|
public SubStageGetterSet(SerializerFixedBinaryLength<T> keySerializer) {
|
|
this.keySerializer = keySerializer;
|
|
}
|
|
|
|
@Override
|
|
public Mono<DatabaseSetDictionary<T>> subStage(LLDictionary dictionary,
|
|
@Nullable CompositeSnapshot snapshot,
|
|
Mono<Send<Buffer>> prefixKeyMono) {
|
|
return prefixKeyMono.map(prefixKeyToReceive -> {
|
|
var prefixKey = prefixKeyToReceive.receive();
|
|
return DatabaseSetDictionary.tail(dictionary, prefixKey, keySerializer, null);
|
|
}).doOnDiscard(Send.class, Send::close).doOnDiscard(Resource.class, Resource::close);
|
|
}
|
|
|
|
public int getKeyBinaryLength() {
|
|
return keySerializer.getSerializedBinaryLength();
|
|
}
|
|
}
|