private static void encode(final Object obj, final RLPOutput out) {
    if (obj instanceof Bytes) {
      out.writeBytes((Bytes) obj);
    } else if (obj instanceof List) {
      final List<?> l = (List<?>) obj;
      out.startList();
      for (final Object o : l) encode(o, out);
      out.endList();
    } else {
      throw new IllegalArgumentException(
          format("Invalid input type %s for RLP encoding", obj.getClass()));
    }
  }
Recursively RLP encode an object consisting of recursive lists of {@link Bytes}. Bytes are
assumed to be non-scalar (leading zeros are not trimmed).

@param obj An object that must be either directly a {@link Bytes}, or a list whose elements are
    either {@link Bytes}, or similarly composed sub-lists.
@return The RLP encoding corresponding to {@code obj}.
@throws IllegalArgumentException if {@code obj} is not a valid input (not entirely composed
    from lists and {@link Bytes}).
ethereum/rlp/src/test-support/java/org/hyperledger/besu/ethereum/rlp/util/RLPTestUtil.java