Search in sources :

Example 6 with FrameHeaderData

use of com.webpieces.http2parser.impl.FrameHeaderData in project webpieces by deanhiller.

the class PriorityMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int streamId = frameHeaderData.getStreamId();
    if (state.getFrameHeaderData().getPayloadLength() != 5)
        throw new StreamException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "priority size not 5 and instead is=" + state.getFrameHeaderData().getPayloadLength());
    PriorityFrame frame = new PriorityFrame();
    PriorityDetails priorityDetails = frame.getPriorityDetails();
    super.unmarshalFrame(state, frame);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(framePayloadData);
    int firstInt = payloadByteBuffer.getInt();
    priorityDetails.setStreamDependencyIsExclusive((firstInt >>> 31) == 0x1);
    int streamDependency = firstInt & 0x7FFFFFFF;
    if (frame.getStreamId() == 0) {
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "priority cannot be streamid 0 and was=" + frame.getStreamId());
    } else if (streamDependency == frame.getStreamId()) {
        // Can't depend on self
        throw new ConnectionException(CancelReasonCode.BAD_STREAM_DEPENDENCY, streamDependency, "stream id=" + streamDependency + " depends on itself");
    }
    priorityDetails.setStreamDependency(streamDependency);
    priorityDetails.setWeight((short) (payloadByteBuffer.get() & 0xFF));
    bufferPool.releaseBuffer(payloadByteBuffer);
    return frame;
}
Also used : FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) PriorityDetails(com.webpieces.http2parser.api.dto.lib.PriorityDetails) PriorityFrame(com.webpieces.http2parser.api.dto.PriorityFrame) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) StreamException(com.webpieces.http2parser.api.dto.error.StreamException)

Aggregations

FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)6 ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)5 ByteBuffer (java.nio.ByteBuffer)5 PingFrame (com.webpieces.http2parser.api.dto.PingFrame)1 PriorityFrame (com.webpieces.http2parser.api.dto.PriorityFrame)1 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)1 SettingsFrame (com.webpieces.http2parser.api.dto.SettingsFrame)1 WindowUpdateFrame (com.webpieces.http2parser.api.dto.WindowUpdateFrame)1 StreamException (com.webpieces.http2parser.api.dto.error.StreamException)1 Http2Setting (com.webpieces.http2parser.api.dto.lib.Http2Setting)1 PriorityDetails (com.webpieces.http2parser.api.dto.lib.PriorityDetails)1