public static Bytes encode(final Consumer<RLPOutput> writer) {
    final BytesValueRLPOutput out = new BytesValueRLPOutput();
    writer.accept(out);
    return out.encoded();
  }
Creates a {@link RLPOutput}, pass it to the provided consumer for writing, and then return the
RLP encoded result of that writing.

<p>This method is a convenience method that is mostly meant for use with class that have a
method to write to an {@link RLPOutput}. For instance:

<pre>{@code
class Foo {
  public void writeTo(RLPOutput out) {
    //... write some data to out ...
  }
}

Foo f = ...;
// RLP encode f
Bytes encoded = RLPs.encode(f::writeTo);
}</pre>

@param writer A method that given an {@link RLPOutput}, writes some data to it.
@return The RLP encoding of the data written by {@code writer}.
ethereum/rlp/src/main/java/org/hyperledger/besu/ethereum/rlp/RLP.java