@Override
    public void intercept(@NonNull HttpResponseChain chain, @NonNull ByteBuffer buffer)
            throws IOException {
        if (chain.response().httpProtocol() == HttpProtocol.HTTP_2) {
            if (mLog == null) {
                HttpResponse response = chain.response();
                mLog = new NetBareXLog(response.protocol(), response.ip(), response.port());
            }
            if (mHpackResponseWriter == null) {
                mHpackResponseWriter = new Hpack.Writer();
            }
            int index;
            int streamId = chain.response().streamId();
            Integer responseIndex = mStreamResponseIndexes.get(streamId);
            if (responseIndex != null) {
                index = responseIndex + 1;
            } else {
                index = 0;
            }
            mStreamResponseIndexes.put(streamId, index);
            if (index == 0) {
                encodeResponseHeader(chain);
            } else {
                encodeResponseData(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