static int extractSize(final IntUnaryOperator getter, final int offset, final int sizeLength) {
    int res = 0;
    int shift = 0;
    for (int i = 0; i < sizeLength; i++) {
      res |= (getter.applyAsInt(offset + (sizeLength - 1) - i) & 0xFF) << shift;
      shift += 8;
    }
    return res;
  }
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