private <T> BiFunction<BytesStore, T, T> fromBytes(@NotNull Class type, @NotNull Function<Bytes, Wire> wireType) { if (type == String.class) return (t, bytes) -> (T) (bytes == null ? null : bytes.toString()); if (Marshallable.class.isAssignableFrom(type)) return (bytes, t) -> { if (bytes == null) return null; t = acquireInstance(type, t); ((Marshallable) t).readMarshallable(wireType.apply(bytes.bytesForRead())); return t; }; throw new UnsupportedOperationException("todo"); }
/** * Convert text to bytes using ISO-8859-1 encoding and return a Bytes ready for reading. * * @param text to convert * @return Bytes ready for reading. */ static Bytes<byte[]> from(@NotNull CharSequence text) { if (text instanceof BytesStore) return ((BytesStore) text).copy().bytesForRead(); return wrapForRead(text.toString().getBytes(StandardCharsets.ISO_8859_1)); }
@Nullable private V bytesToValue(@Nullable BytesStore oldValue) { @Nullable V ret; if (oldValue != null) { V using = createValue.get(); using.readMarshallable(new TextWire(oldValue.bytesForRead())); ret = using; } else { ret = null; } return ret; }
/** * Creates a slice of the current Bytes based on its position() and limit(). As a sub-section * of a Bytes it cannot be elastic. * * @return a slice of the existing Bytes where the start is moved to the position and the * current limit determines the capacity. * @throws IllegalStateException if the underlying BytesStore has been released */ @NotNull @Override default Bytes<Underlying> bytesForRead() throws IllegalStateException { return isClear() ? BytesStore.super.bytesForRead() : new SubBytes<>(this, readPosition(), readLimit() + start()); }
BytesStore<?, ByteBuffer> bs = BytesStore.wrap(byteBuffer); try { Bytes<ByteBuffer> bbb = bs.bytesForRead(); bbb.readLimit(byteBuffer.limit()); bbb.readPosition(byteBuffer.position());
@Override default void writeMarshallable(@NotNull final WireOut wire) { wire.write(() -> "key").bytes(key()); if (ENGINE_REPLICATION_COMPRESSION != null && value() != null) wire.write(() -> "value").compress(ENGINE_REPLICATION_COMPRESSION, value().bytesForRead()); else wire.write(() -> "value").bytes(value()); wire.write(() -> "timestamp").int64(timestamp()); wire.write(() -> "identifier").int8(identifier()); wire.write(() -> "isDeleted").bool(isDeleted()); wire.write(() -> "bootStrapTimeStamp").int64(bootStrapTimeStamp()); wire.writeComment("remoteIdentifier=" + remoteIdentifier()); } }