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

com.fireflysource.net.http.common.v2.encoder.WindowUpdateGenerator 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.Flags;
import com.fireflysource.net.http.common.v2.frame.Frame;
import com.fireflysource.net.http.common.v2.frame.FrameType;
import com.fireflysource.net.http.common.v2.frame.WindowUpdateFrame;

import java.nio.ByteBuffer;
import java.util.LinkedList;

public class WindowUpdateGenerator extends FrameGenerator {
    public WindowUpdateGenerator(HeaderGenerator headerGenerator) {
        super(headerGenerator);
    }

    @Override
    public FrameBytes generate(Frame frame) {
        WindowUpdateFrame windowUpdateFrame = (WindowUpdateFrame) frame;
        return generateWindowUpdate(windowUpdateFrame.getStreamId(), windowUpdateFrame.getWindowDelta());
    }

    public FrameBytes generateWindowUpdate(int streamId, int windowUpdate) {
        if (windowUpdate < 0)
            throw new IllegalArgumentException("Invalid window update: " + windowUpdate);

        ByteBuffer header = generateHeader(FrameType.WINDOW_UPDATE, WindowUpdateFrame.WINDOW_UPDATE_LENGTH, Flags.NONE, streamId);
        header.putInt(windowUpdate);
        BufferUtils.flipToFlush(header, 0);

        FrameBytes frameBytes = new FrameBytes();
        frameBytes.setByteBuffers(new LinkedList<>());
        frameBytes.getByteBuffers().add(header);
        frameBytes.setLength(Frame.HEADER_LENGTH + WindowUpdateFrame.WINDOW_UPDATE_LENGTH);
        return frameBytes;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy