static RLPElementMetadata rlpElementMetadata(
      final LongUnaryOperator byteGetter, final long size, final long elementStart) {
    final int prefix = Math.toIntExact(byteGetter.applyAsLong(elementStart)) & 0xFF;
    final Kind kind = Kind.of(prefix);
    long payloadStart = 0;
    int payloadSize = 0;

    switch (kind) {
      case BYTE_ELEMENT:
        payloadStart = elementStart;
        payloadSize = 1;
        break;
      case SHORT_ELEMENT:
        payloadStart = elementStart + 1;
        payloadSize = prefix - 0x80;
        break;
      case LONG_ELEMENT:
        final int sizeLengthElt = prefix - 0xb7;
        payloadStart = elementStart + 1 + sizeLengthElt;
        payloadSize = readLongSize(byteGetter, size, elementStart, sizeLengthElt);
        break;
      case SHORT_LIST:
        payloadStart = elementStart + 1;
        payloadSize = prefix - 0xc0;
        break;
      case LONG_LIST:
        final int sizeLengthList = prefix - 0xf7;
        payloadStart = elementStart + 1 + sizeLengthList;
        payloadSize = readLongSize(byteGetter, size, elementStart, sizeLengthList);
        break;
    }

    return new RLPElementMetadata(kind, elementStart, payloadStart, payloadSize);
  }
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