2021-10-15 22:03:53 +02:00
|
|
|
package it.cavallium.dbengine.lucene;
|
|
|
|
|
2022-10-02 03:09:50 +02:00
|
|
|
import io.netty5.buffer.Buffer;
|
2021-10-15 22:03:53 +02:00
|
|
|
import java.util.function.Function;
|
|
|
|
import org.apache.lucene.util.BytesRef;
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
public class BytesRefCodec implements HugePqCodec<BytesRef> {
|
2021-10-15 22:03:53 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-06 02:41:32 +02:00
|
|
|
public Buffer serialize(Function<Integer, Buffer> allocator, BytesRef data) {
|
2021-10-15 22:03:53 +02:00
|
|
|
var buf = allocator.apply(data.length + Integer.BYTES);
|
|
|
|
buf.writeInt(data.length);
|
|
|
|
buf.writeBytes(data.bytes, data.offset, data.length);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-06 02:41:32 +02:00
|
|
|
public BytesRef deserialize(Buffer b) {
|
2021-10-15 22:03:53 +02:00
|
|
|
var length = b.readInt();
|
|
|
|
var bytes = new byte[length];
|
|
|
|
b.readBytes(bytes, 0, length);
|
|
|
|
return new BytesRef(bytes, 0, length);
|
|
|
|
}
|
2022-04-06 02:41:32 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BytesRef clone(BytesRef obj) {
|
|
|
|
return obj.clone();
|
|
|
|
}
|
2021-10-15 22:03:53 +02:00
|
|
|
}
|