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

24 lines
540 B
Java
Raw Normal View History

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