private static int extractSizeFromLongItem(
      final LongUnaryOperator getter, final long offset, final int sizeLength) {
    if (sizeLength > 4) {
      throw new RLPException(
          "RLP item at offset "
              + offset
              + " with size value consuming "
              + sizeLength
              + " bytes exceeds max supported size of "
              + Integer.MAX_VALUE);
    }

    long res = 0;
    int shift = 0;
    for (int i = 0; i < sizeLength; i++) {
      res |= (getter.applyAsLong(offset + (sizeLength - 1) - i) & 0xFF) << shift;
      shift += 8;
    }
    try {
      return Math.toIntExact(res);
    } catch (final ArithmeticException e) {
      throw new RLPException(
          "RLP item at offset "
              + offset
              + " with size value consuming "
              + sizeLength
              + " bytes exceeds max supported size of "
              + Integer.MAX_VALUE,
          e);
    }
  }
Read from the provided offset a size of the provided length, assuming this is enough bytes.
ethereum/rlp/src/main/java/org/hyperledger/besu/ethereum/rlp/RLPDecodingHelpers.java