private void decodeSettings(ByteBuffer buffer, int length, byte flags, int streamId,
                                Http2Updater receiver)
            throws IOException {
        if (streamId != 0) {
            throw new IOException("Http2 TYPE_SETTINGS streamId != 0");
        }
        if ((flags & Http2.FLAG_ACK) != 0) {
            if (length != 0) {
                throw new IOException("Http2 FRAME_SIZE_ERROR ack frame should be empty!");
            }
            mLog.i("Http2 ack the settings");
            return;
        }
        if (length % 6 != 0) {
            throw new IOException("Http2 TYPE_SETTINGS length %% 6 != 0: " + length);
        }
        int initPosition = buffer.position();
        Http2Settings settings = new Http2Settings();
        for (int i = 0; i < length; i += 6) {
            int id = buffer.getShort() & 0xFFFF;
            int value = buffer.getInt();
            switch (id) {
                case 1: // SETTINGS_HEADER_TABLE_SIZE
                    mLog.i("Http2 SETTINGS_HEADER_TABLE_SIZE: " + value);
                    break;
                case 2: // SETTINGS_ENABLE_PUSH
                    if (value != 0 && value != 1) {
                        throw new IOException("Http2 PROTOCOL_ERROR SETTINGS_ENABLE_PUSH != 0 or 1");
                    }
                    break;
                case 3: // SETTINGS_MAX_CONCURRENT_STREAMS
                    id = 4; // Renumbered in draft 10.
                    mLog.i("Http2 SETTINGS_MAX_CONCURRENT_STREAMS: " + value);
                    break;
                case 4: // SETTINGS_INITIAL_WINDOW_SIZE
                    id = 7; // Renumbered in draft 10.
                    if (value < 0) {
                        throw new IOException("Http2 PROTOCOL_ERROR SETTINGS_INITIAL_WINDOW_SIZE > 2^31 - 1");
                    }
                    mLog.i("Http2 SETTINGS_INITIAL_WINDOW_SIZE: " + value);
                    break;
                case 5: // SETTINGS_MAX_FRAME_SIZE
                    if (value < Http2.INITIAL_MAX_FRAME_SIZE || value > 16777215) {
                        throw new IOException("Http2 PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: " + value);
                    }
                    mLog.i("Http2 INITIAL_MAX_FRAME_SIZE: " + value);
                    break;
                case 6: // SETTINGS_MAX_HEADER_LIST_SIZE
                    break; // Advisory only, so ignored.
                default:
                    break; // Must ignore setting with unknown id.
            }
            settings.set(id, value);
        }
        // Reverse the position and sent to terminal.
        buffer.position(initPosition);
        receiver.onSettingsUpdate(settings);
    }
Decodes HTTP2 request and response packets.

@author Megatron King
@since 2019/1/5 14:19
netbare-core/src/main/java/com/github/megatronking/netbare/http2/Http2DecodeInterceptor.java