All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fireflysource.net.http.common.v2.encoder.HeaderGenerator Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package com.fireflysource.net.http.common.v2.encoder;

import com.fireflysource.common.io.BufferUtils;
import com.fireflysource.net.http.common.v2.frame.Frame;
import com.fireflysource.net.http.common.v2.frame.FrameType;

import java.nio.ByteBuffer;

public class HeaderGenerator {
    private int maxFrameSize = Frame.DEFAULT_MAX_LENGTH;

    public ByteBuffer generate(FrameType frameType, int capacity, int length, int flags, int streamId) {
        ByteBuffer header = BufferUtils.allocate(capacity);
        BufferUtils.flipToFill(header);
        header.put((byte) ((length & 0x00_FF_00_00) >>> 16));
        header.put((byte) ((length & 0x00_00_FF_00) >>> 8));
        header.put((byte) ((length & 0x00_00_00_FF)));
        header.put((byte) frameType.getType());
        header.put((byte) flags);
        header.putInt(streamId);
        return header;
    }

    public int getMaxFrameSize() {
        return maxFrameSize;
    }

    public void setMaxFrameSize(int maxFrameSize) {
        this.maxFrameSize = maxFrameSize;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy