28 lines
850 B
Java
28 lines
850 B
Java
package org.warp.jcwdb;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import net.openhft.hashing.LongHashFunction;
|
|
|
|
public class DBStringParser extends DBTypeParserImpl<String> {
|
|
private static final LongHashFunction hashFunction = net.openhft.hashing.LongHashFunction.xx();
|
|
private static final DBReader<String> defaultReader = (i, size) -> {
|
|
return new String(i.readBytes(size), StandardCharsets.UTF_16LE);
|
|
};
|
|
|
|
public DBReader<String> getReader() {
|
|
return defaultReader;
|
|
}
|
|
|
|
public DBDataOutput<String> getWriter(final String value) {
|
|
return DBDataOutput.create((o) -> {
|
|
o.write(value.getBytes(StandardCharsets.UTF_16LE));
|
|
}, DBStandardTypes.STRING, value.length() * 2, calculateHash(value));
|
|
}
|
|
|
|
@Override
|
|
public long calculateHash(String value) {
|
|
return hashFunction.hashBytes(value.getBytes(StandardCharsets.UTF_16LE));
|
|
}
|
|
}
|