static <T extends Streamable> Writeable.Reader<T> newWriteableReader(Supplier<T> supplier) { return (StreamInput in) -> { T request = supplier.get(); request.readFrom(in); return request; }; } }
/** * Read a {@link List} of {@link Streamable} objects, using the {@code constructor} to instantiate each instance. * <p> * This is expected to take the form: * <code> * List<MyStreamableClass> list = in.readStreamList(MyStreamableClass::new); * </code> * * @param constructor Streamable instance creator * @return Never {@code null}. * @throws IOException if any step fails */ public <T extends Streamable> List<T> readStreamableList(Supplier<T> constructor) throws IOException { int count = readArraySize(); List<T> builder = new ArrayList<>(count); for (int i=0; i<count; i++) { T instance = constructor.get(); instance.readFrom(this); builder.add(instance); } return builder; }
/** * Serializes a potential null value. */ @Nullable public <T extends Streamable> T readOptionalStreamable(Supplier<T> supplier) throws IOException { if (readBoolean()) { T streamable = supplier.get(); streamable.readFrom(this); return streamable; } else { return null; } }
static <T extends Streamable> Writeable.Reader<T> newWriteableReader(Supplier<T> supplier) { return (StreamInput in) -> { T request = supplier.get(); request.readFrom(in); return request; }; } }
static <T extends Streamable> Writeable.Reader<T> newWriteableReader(Supplier<T> supplier) { return (StreamInput in) -> { T request = supplier.get(); request.readFrom(in); return request; }; } }
/** * Serializes a potential null value. */ public <T extends Streamable> T readOptionalStreamable(T streamable) throws IOException { if (readBoolean()) { streamable.readFrom(this); return streamable; } else { return null; } }
/** * Read a {@link List} of {@link Streamable} objects, using the {@code constructor} to instantiate each instance. * <p> * This is expected to take the form: * <code> * List<MyStreamableClass> list = in.readStreamList(MyStreamableClass::new); * </code> * * @param constructor Streamable instance creator * @return Never {@code null}. * @throws IOException if any step fails */ public <T extends Streamable> List<T> readStreamableList(Supplier<T> constructor) throws IOException { int count = readArraySize(); List<T> builder = new ArrayList<>(count); for (int i=0; i<count; i++) { T instance = constructor.get(); instance.readFrom(this); builder.add(instance); } return builder; }
/** * Read a {@link List} of {@link Streamable} objects, using the {@code constructor} to instantiate each instance. * <p> * This is expected to take the form: * <code> * List<MyStreamableClass> list = in.readStreamList(MyStreamableClass::new); * </code> * * @param constructor Streamable instance creator * @return Never {@code null}. * @throws IOException if any step fails */ public <T extends Streamable> List<T> readStreamableList(Supplier<T> constructor) throws IOException { int count = readArraySize(); List<T> builder = new ArrayList<>(count); for (int i=0; i<count; i++) { T instance = constructor.get(); instance.readFrom(this); builder.add(instance); } return builder; }
/** * Read a {@link List} of {@link Streamable} objects, using the {@code constructor} to instantiate each instance. * <p> * This is expected to take the form: * <code> * List<MyStreamableClass> list = in.readStreamList(MyStreamableClass::new); * </code> * * @param constructor Streamable instance creator * @return Never {@code null}. * @throws IOException if any step fails */ public <T extends Streamable> List<T> readStreamableList(Supplier<T> constructor) throws IOException { int count = readArraySize(); List<T> builder = new ArrayList<>(count); for (int i=0; i<count; i++) { T instance = constructor.get(); instance.readFrom(this); builder.add(instance); } return builder; }
/** * Serializes a potential null value. */ @Nullable public <T extends Streamable> T readOptionalStreamable(Supplier<T> supplier) throws IOException { if (readBoolean()) { T streamable = supplier.get(); streamable.readFrom(this); return streamable; } else { return null; } }
/** * Serializes a potential null value. */ @Nullable public <T extends Streamable> T readOptionalStreamable(Supplier<T> supplier) throws IOException { if (readBoolean()) { T streamable = supplier.get(); streamable.readFrom(this); return streamable; } else { return null; } }
/** * Serializes a potential null value. */ @Nullable public <T extends Streamable> T readOptionalStreamable(Supplier<T> supplier) throws IOException { if (readBoolean()) { T streamable = supplier.get(); streamable.readFrom(this); return streamable; } else { return null; } }
/** * Round trip {@code instance} through binary serialization, setting the wire compatibility version to {@code version}. */ private T copyInstance(T instance, Version version) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { output.setVersion(version); instance.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), getNamedWriteableRegistry())) { in.setVersion(version); T newInstance = createBlankInstance(); newInstance.readFrom(in); return newInstance; } } }
newInstance.readFrom(input); assertThat("Stream should be fully read with version [" + version + "] for streamable [" + streamable + "]", input.available(), equalTo(0));