CavalliumDBEngine/src/main/java/it/cavallium/dbengine/lucene/ByteArrayCodec.java

29 lines
627 B
Java
Raw Normal View History

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