public void writeEncoded(final MutableBytes mutableBytes) {
    // Special case where we encode only a single non-list item (note that listsCount is initially
    // set to 1, so listsCount == 1 really mean no list explicitly added to the output).
    if (listsCount == 1) {
      // writeBytes make sure we cannot have more than 1 value without a list
      assert values.size() == 1;
      final Bytes value = values.get(0);

      final int finalOffset;
      // Single non-list value.
      if (rlpEncoded.get(0)) {
        value.copyTo(mutableBytes, 0);
        finalOffset = value.size();
      } else {
        finalOffset = RLPEncodingHelpers.writeElement(value, mutableBytes, 0);
      }
      checkState(
          finalOffset == mutableBytes.size(),
          "Expected single element RLP encode to be of size %s but was of size %s.",
          mutableBytes.size(),
          finalOffset);
      return;
    }

    int offset = 0;
    int listIdx = 0;
    for (int i = 0; i < values.size(); i++) {
      final Bytes value = values.get(i);
      if (value == LIST_MARKER) {
        final int payloadSize = payloadSizes[++listIdx];
        offset = RLPEncodingHelpers.writeListHeader(payloadSize, mutableBytes, offset);
      } else if (rlpEncoded.get(i)) {
        value.copyTo(mutableBytes, offset);
        offset += value.size();
      } else {
        offset = RLPEncodingHelpers.writeElement(value, mutableBytes, offset);
      }
    }

    checkState(
        offset == mutableBytes.size(),
        "Expected RLP encoding to be of size %s but was of size %s.",
        mutableBytes.size(),
        offset);
  }
Write the rlp encoded value to the provided {@link MutableBytes}

@param mutableBytes the value to which the rlp-data will be written
ethereum/rlp/src/main/java/org/hyperledger/besu/ethereum/rlp/AbstractRLPOutput.java