package it.cavallium.dbengine.client; import io.netty.buffer.ByteBuf; import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength; import org.jetbrains.annotations.NotNull; public class MappedSerializerFixedLength implements SerializerFixedBinaryLength { private final SerializerFixedBinaryLength fixedLengthSerializer; private final Mapper keyMapper; public MappedSerializerFixedLength(SerializerFixedBinaryLength fixedLengthSerializer, Mapper keyMapper) { this.fixedLengthSerializer = fixedLengthSerializer; this.keyMapper = keyMapper; } @Override public @NotNull B deserialize(@NotNull ByteBuf serialized) { try { return keyMapper.map(fixedLengthSerializer.deserialize(serialized.retain())); } finally { serialized.release(); } } @Override public @NotNull ByteBuf serialize(@NotNull B deserialized) { return fixedLengthSerializer.serialize(keyMapper.unmap(deserialized)); } @Override public int getSerializedBinaryLength() { return fixedLengthSerializer.getSerializedBinaryLength(); } }