// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_CONTINUATION_FRAME = 0x09;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DATA_FRAME = 0x00;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DEFAULT_DEPENDENCY = 0;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DEFAULT_WEIGHT = 16;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_ACK = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_END_HEADERS = 0x04;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_END_STREAM = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_PRIORITY = 0x20;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_FRAME_HEADER_SIZE = 9;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_GOAWAY_FRAME = 0x07;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_HEADERS_FRAME = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_MAX_LENGTH = 0x4000; // Initial MAX_FRAME_SIZE value is 2^14
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PING_FRAME = 0x06;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PRIORITY_FRAME = 0x02;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PUSH_PROMISE_FRAME = 0x05;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_RST_STREAM_FRAME = 0x03;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_SETTINGS_FRAME = 0x04;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_WINDOW_UPDATE_FRAME = 0x08;


import java.util.Set;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import static com.twitter.http2.HttpCodecUtil.HTTP_CONTINUATION_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_DATA_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_DEFAULT_DEPENDENCY;
import static com.twitter.http2.HttpCodecUtil.HTTP_DEFAULT_WEIGHT;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_ACK;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_END_HEADERS;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_END_STREAM;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_PRIORITY;
import static com.twitter.http2.HttpCodecUtil.HTTP_FRAME_HEADER_SIZE;
import static com.twitter.http2.HttpCodecUtil.HTTP_GOAWAY_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_HEADERS_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_MAX_LENGTH;
import static com.twitter.http2.HttpCodecUtil.HTTP_PING_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_PRIORITY_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_PUSH_PROMISE_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_RST_STREAM_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_SETTINGS_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_WINDOW_UPDATE_FRAME;
    /**
     * Encode an HTTP/2 PING Frame
     */
    public ByteBuf encodePingFrame(long data, boolean ack) {
        int length = 8;
        byte flags = ack ? HTTP_FLAG_ACK : 0;
        int streamId = 0;
        ByteBuf frame = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE + length);
        writeFrameHeader(frame, length, HTTP_PING_FRAME, flags, streamId);
        frame.writeLong(data);
        return frame;
    }

    /**
     * Encode an HTTP/2 GOAWAY Frame
     */
    public ByteBuf encodeGoAwayFrame(int lastStreamId, int errorCode) {
        int length = 8;
        byte flags = 0;
        int streamId = 0;
        ByteBuf frame = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE + length);
        writeFrameHeader(frame, length, HTTP_GOAWAY_FRAME, flags, streamId);
        frame.writeInt(lastStreamId);
        frame.writeInt(errorCode);
        return frame;
    }

    /**
     * Encode an HTTP/2 WINDOW_UPDATE Frame
     */
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_CONTINUATION_FRAME = 0x09;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DATA_FRAME = 0x00;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DEFAULT_DEPENDENCY = 0;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DEFAULT_WEIGHT = 16;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_ACK = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_END_HEADERS = 0x04;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_END_STREAM = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_PRIORITY = 0x20;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_FRAME_HEADER_SIZE = 9;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_GOAWAY_FRAME = 0x07;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_HEADERS_FRAME = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_MAX_LENGTH = 0x4000; // Initial MAX_FRAME_SIZE value is 2^14
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PING_FRAME = 0x06;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PRIORITY_FRAME = 0x02;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PUSH_PROMISE_FRAME = 0x05;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_RST_STREAM_FRAME = 0x03;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_SETTINGS_FRAME = 0x04;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_WINDOW_UPDATE_FRAME = 0x08;


// Path: src/main/java/com/twitter/http2/HttpFrameEncoder.java
import java.util.Set;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import static com.twitter.http2.HttpCodecUtil.HTTP_CONTINUATION_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_DATA_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_DEFAULT_DEPENDENCY;
import static com.twitter.http2.HttpCodecUtil.HTTP_DEFAULT_WEIGHT;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_ACK;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_END_HEADERS;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_END_STREAM;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_PRIORITY;
import static com.twitter.http2.HttpCodecUtil.HTTP_FRAME_HEADER_SIZE;
import static com.twitter.http2.HttpCodecUtil.HTTP_GOAWAY_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_HEADERS_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_MAX_LENGTH;
import static com.twitter.http2.HttpCodecUtil.HTTP_PING_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_PRIORITY_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_PUSH_PROMISE_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_RST_STREAM_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_SETTINGS_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_WINDOW_UPDATE_FRAME;

    /**
     * Encode an HTTP/2 PING Frame
     */
    public ByteBuf encodePingFrame(long data, boolean ack) {
        int length = 8;
        byte flags = ack ? HTTP_FLAG_ACK : 0;
        int streamId = 0;
        ByteBuf frame = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE + length);
        writeFrameHeader(frame, length, HTTP_PING_FRAME, flags, streamId);
        frame.writeLong(data);
        return frame;
    }

    /**
     * Encode an HTTP/2 GOAWAY Frame
     */
    public ByteBuf encodeGoAwayFrame(int lastStreamId, int errorCode) {
        int length = 8;
        byte flags = 0;
        int streamId = 0;
        ByteBuf frame = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE + length);
        writeFrameHeader(frame, length, HTTP_GOAWAY_FRAME, flags, streamId);
        frame.writeInt(lastStreamId);
        frame.writeInt(errorCode);
        return frame;
    }

    /**
     * Encode an HTTP/2 WINDOW_UPDATE Frame
     */
    public ByteBuf encodeWindowUpdateFrame(int streamId, int windowSizeIncrement) {