static String[] decodeProtocols(byte[] protocols) {
        if (protocols.length == 0) {
            return EmptyArray.STRING;
        }

        int numProtocols = 0;
        for (int i = 0; i < protocols.length;) {
            int protocolLength = protocols[i];
            if (protocolLength < 0 || protocolLength > protocols.length - i) {
                throw new IllegalArgumentException(
                    "Protocol has invalid length (" + protocolLength + " at position " + i
                        + "): " + (protocols.length < 50
                        ? Arrays.toString(protocols) : protocols.length + " byte array"));
            }

            numProtocols++;
            i += 1 + protocolLength;
        }

        String[] decoded = new String[numProtocols];
        for (int i = 0, d = 0; i < protocols.length;) {
            int protocolLength = protocols[i];
            decoded[d++] = protocolLength > 0
                    ? new String(protocols, i + 1, protocolLength, US_ASCII)
                    : "";
            i += 1 + protocolLength;
        }

        return decoded;
    }
Decodes the given list of protocols into {@link String}s.
@param protocols the encoded protocol list
@return the decoded protocols or {@link EmptyArray#BYTE} if {@code protocols} is
empty.
@throws NullPointerException if protocols is {@code null}.
common/src/main/java/org/conscrypt/SSLUtils.java