@Override
    protected void intercept(@NonNull final HttpRequestChain chain, @NonNull ByteBuffer buffer,
                             int index) throws IOException {
        if (chain.request().httpProtocol() == HttpProtocol.HTTP_2) {
            if (!buffer.hasRemaining()) {
                return;
            }
            if (mLog == null) {
                HttpRequest request = chain.request();
                mLog = new NetBareXLog(request.protocol(), request.ip(), request.port());
            }
            if (mHpackRequestReader == null) {
                mHpackRequestReader = new Hpack.Reader();
            }
            decode(mergeRequestBuffer(buffer), mHpackRequestReader, new DecodeCallback() {

                @Override
                public void onPending(ByteBuffer buffer) {
                    pendRequestBuffer(buffer);
                }

                @Override
                public void onResult(ByteBuffer buffer, boolean isFinished) throws IOException {
                    int streamId = mRequestStream.id;
                    if (streamId < 0) {
                        throw new IOException("Http2 stream id is < 0");
                    }
                    HttpId id = mHttpIds.get(streamId);
                    if (id == null) {
                        id = new HttpId(streamId);
                        mHttpIds.put(streamId, id);
                    }
                    mZygoteRequest.zygote(id);
                    if (isFinished) {
                        mZygoteRequest.onStreamFinished();
                    }
                    if (!buffer.hasRemaining()) {
                        return;
                    }
                    chain.process(buffer);
                }

                @Override
                public void onSkip(ByteBuffer buffer) throws IOException {
                    mRefluxCallback.onRequest(chain.request(), buffer);
                }

            }, mRequestStream, new Http2Updater() {
                @Override
                public void onSettingsUpdate(Http2Settings http2Settings) {
                    mZygoteRequest.onSettingsUpdate(http2Settings);
                    if (http2Settings.getHeaderTableSize() > 0) {
                        if (mHpackResponseReader == null) {
                            mHpackResponseReader = new Hpack.Reader();
                        }
                        mHpackResponseReader.setHeaderTableSizeSetting(http2Settings.getHeaderTableSize());
                    }
                }

                @Override
                public void onStreamFinished() {
                    mZygoteRequest.onStreamFinished();
                }
            });
        } else {
            chain.process(buffer);
        }
    }
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