code: private int extractNextTlvElementLength(IoBuffer in) {
          if (!hasRemainingData(in, 2)) {
              return NOT_ENOUGH_DATA;
          }
          try {
              in.mark();
              int firstByte = in.getUnsigned();
              boolean tlv8 = (firstByte & TLV16_MASK) == 0;
              if (tlv8) {
                  // 8 bit length. NB! Reads one unsigned byte as an integer
                  return in.getUnsigned() + TLV8_HEADER_LENGTH;
              }
              // skip tlv16 LSB byte
              in.skip(1);
              if (!hasRemainingData(in, 2)) {
                  return NOT_ENOUGH_DATA;
              }
              // 16 bit length. NB! Reads two bytes unsigned integer
              return in.getUnsignedShort() + TLV16_HEADER_LENGTH;
          } finally {
              in.reset();
          }
      }
docs: Returns the length of the next TLV element. Returns -1 when buffer doesn't contain enough data for next TLV
  element.
  
  @return The length of the TLV element.