Search in sources :

Example 96 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class HpackParserImpl method translate.

private DataWrapper translate(List<Http2Frame> headerFrames) {
    DataWrapper allData = DataWrapperGeneratorFactory.EMPTY;
    for (Http2Frame f : headerFrames) {
        DataWrapper frameData = parser.marshal(f);
        allData = dataGen.chainDataWrappers(allData, frameData);
    }
    return allData;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame)

Example 97 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class DataMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    DataFrame castFrame = (DataFrame) frame;
    int paddingSize = castFrame.getPadding().getReadableSize();
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "data frame had invalid stream id=" + frame.getStreamId());
    byte value = (byte) 0x0;
    if (castFrame.isEndOfStream())
        value |= 0x1;
    if (paddingSize > 0)
        value |= 0x8;
    DataWrapper dataPayload = PaddingUtil.padDataIfNeeded(castFrame.getData(), castFrame.getPadding());
    return super.marshalFrame(frame, value, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 98 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class GoAwayMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("GoAwayFrame can never be any other stream id except 0 which is already set");
    GoAwayFrame castFrame = (GoAwayFrame) frame;
    long originalStreamId = castFrame.getLastStreamId();
    long streamId = originalStreamId & 0x7FFFFFFF;
    if (streamId != originalStreamId)
        throw new RuntimeException("your lastStreamId is too large per spec. frame=" + frame);
    ByteBuffer prelude = bufferPool.nextBuffer(8);
    UnsignedData.putUnsignedInt(prelude, castFrame.getLastStreamId());
    UnsignedData.putUnsignedInt(prelude, castFrame.getErrorCode());
    prelude.flip();
    DataWrapper debug = dataGen.emptyWrapper();
    if (castFrame.getDebugData() != null)
        debug = castFrame.getDebugData();
    DataWrapper payload = dataGen.chainDataWrappers(dataGen.wrapByteBuffer(prelude), debug);
    return super.marshalFrame(frame, (byte) 0, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame)

Example 99 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class Http2ParserImpl method parse.

@Override
public Http2Memento parse(Http2Memento memento, DataWrapper newData) {
    Http2MementoImpl state = (Http2MementoImpl) memento;
    state.getParsedFrames().clear();
    DataWrapper allData = dataGen.chainDataWrappers(state.getLeftOverData(), newData);
    state.setLeftOverData(allData);
    while (true) {
        switch(state.getParsingState()) {
            case NEED_PARSE_FRAME_HEADER:
                if (!parseFrameHeader(state))
                    return state;
                else
                    state.setParsingState(ParsingState.NEED_PARSE_BODY);
                break;
            case NEED_PARSE_BODY:
                if (!parseBody(state))
                    return state;
                else
                    state.setParsingState(ParsingState.NEED_PARSE_FRAME_HEADER);
                break;
        }
    }
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper)

Example 100 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class AbstractFrameMarshaller method marshalFrame.

protected DataWrapper marshalFrame(Http2Frame frame, byte value, DataWrapper payload) {
    int originalStreamId = frame.getStreamId();
    // Clear the MSB because streamId can only be 31 bits
    int streamId = originalStreamId & 0x7FFFFFFF;
    if (streamId != originalStreamId)
        throw new RuntimeException("your stream id is too large per spec. frame=" + frame);
    ByteBuffer header = ByteBuffer.allocate(9);
    int length = payload.getReadableSize();
    header.put((byte) (length >>> 16));
    header.putShort((short) length);
    header.put(frame.getFrameType().getId());
    header.put(value);
    // 1 bit reserved, streamId MSB is always 0, see setStreamId()
    header.putInt(streamId);
    header.flip();
    DataWrapper frameHeader = dataGen.wrapByteBuffer(header);
    return dataGen.chainDataWrappers(frameHeader, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer)

Aggregations

DataWrapper (org.webpieces.data.api.DataWrapper)115 Test (org.junit.Test)47 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)22 ByteBuffer (java.nio.ByteBuffer)20 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)18 Header (org.webpieces.httpparser.api.common.Header)17 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)17 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)16 HttpData (org.webpieces.httpparser.api.dto.HttpData)15 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)12 Http2Request (com.webpieces.hpack.api.dto.Http2Request)10 StreamWriter (com.webpieces.http2engine.api.StreamWriter)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)7 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)7 Http2Response (com.webpieces.hpack.api.dto.Http2Response)6 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)6 ArrayList (java.util.ArrayList)6 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)5