package org.warp.jcwdb; import java.nio.charset.StandardCharsets; import net.openhft.hashing.LongHashFunction; public class DBStringParser extends DBTypeParserImpl { private static final LongHashFunction hashFunction = net.openhft.hashing.LongHashFunction.xx(); private static final DBReader defaultReader = (i, size) -> { return new String(i.readBytes(size), StandardCharsets.UTF_16LE); }; public DBReader getReader() { return defaultReader; } public DBDataOutput 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)); } }