@Override
    public void intercept(@NonNull HttpRequestChain chain, @NonNull ByteBuffer buffer)
            throws IOException {
        if (chain.request().httpProtocol() == HttpProtocol.HTTP_2) {
            if (mLog == null) {
                HttpRequest request = chain.request();
                mLog = new NetBareXLog(request.protocol(), request.ip(), request.port());
            }
            if (mHpackRequestWriter == null) {
                mHpackRequestWriter = new Hpack.Writer();
            }
            int index;
            int streamId = chain.request().streamId();
            Integer requestIndex = mStreamRequestIndexes.get(streamId);
            if (requestIndex != null) {
                index = requestIndex + 1;
            } else {
                index = 0;
            }
            mStreamRequestIndexes.put(streamId, index);
            if (index == 0) {
                encodeRequestHeader(chain);
            } else {
                encodeRequestData(chain, buffer);
            }
        } else {
            chain.process(buffer);
        }

    }
Encodes HTTP2 request and response packets.

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