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

com.firefly.codec.http2.encode.ResetGenerator Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.codec.http2.encode;

import com.firefly.codec.http2.frame.Flags;
import com.firefly.codec.http2.frame.Frame;
import com.firefly.codec.http2.frame.FrameType;
import com.firefly.codec.http2.frame.ResetFrame;
import com.firefly.utils.io.BufferUtils;

import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;

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

    @Override
    public List generate(Frame frame) {
        ResetFrame resetFrame = (ResetFrame) frame;
        return Collections.singletonList(generateReset(resetFrame.getStreamId(), resetFrame.getError()));
    }

    public ByteBuffer generateReset(int streamId, int error) {
        if (streamId < 0)
            throw new IllegalArgumentException("Invalid stream id: " + streamId);

        ByteBuffer header = generateHeader(FrameType.RST_STREAM, 4, Flags.NONE, streamId);
        header.putInt(error);
        BufferUtils.flipToFlush(header, 0);
        return header;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy