private static <T> BiFunction<T, Bytes, Bytes> toBytes(Class type) { if (type == String.class) return (t, bytes) -> (Bytes) bytes.appendUtf8((String) t); throw new UnsupportedOperationException("todo"); }
static <T> BiFunction<T, Bytes, Bytes> toBytes(@NotNull Class type, @NotNull Function<Bytes, Wire> wireType) { if (type == String.class) return (t, bytes) -> (Bytes) bytes.appendUtf8((String) t); if (Marshallable.class.isAssignableFrom(type)) return (t, bytes) -> { t = acquireInstance(type, t); ((Marshallable) t).writeMarshallable(wireType.apply(bytes)); return bytes; }; throw new UnsupportedOperationException("todo"); }
@Nullable @Override public String getAndPut(String key, @NotNull String value) { Buffers b = BUFFERS.get(); Bytes<ByteBuffer> bytes = b.valueBuffer; bytes.clear(); bytes.appendUtf8(value); @Nullable BytesStore retBytes = kvStore.getAndPut(key, bytes); if (retBytes == null) return null; else { String s = retBytes.toString(); retBytes.release(); return s; } }
public static <ACS extends Appendable & CharSequence> void append(ACS a, CharSequence cs, long start, long len) { if (a instanceof StringBuilder) { if (cs instanceof Bytes) ((StringBuilder) a).append(Bytes.toString(((Bytes) cs), start, len)); else ((StringBuilder) a).append(cs.subSequence(Maths.toInt32(start), Maths.toInt32(len))); } else if (a instanceof Bytes) { ((Bytes) a).appendUtf8(cs, Maths.toInt32(start), Maths.toInt32(len)); } else { throw new UnsupportedOperationException(); } }
public static void write(@NotNull Bytes bytes, long capacity) { long start = bytes.writePosition(); bytes.write(SECTION1); bytes.append(capacity); while (bytes.writePosition() - start < CAPACITY + DIGITS) { bytes.writeUnsignedByte(' '); } bytes.write(SECTION2); bytes.write(ZERO); bytes.write(SECTION3); for (long i = 0; i < capacity; i++) { if (i > 0) bytes.appendUtf8(", "); bytes.write(ZERO); } bytes.write(SECTION4); }