Search in sources :

Example 1 with Http2FrameType

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2FrameType in project webpieces by deanhiller.

the class Http2ParserImpl method marshal.

// private int getStreamId(DataWrapper data) {
// 
// ByteBuffer streamIdBuffer = bufferPool.nextBuffer(4);
// streamIdBuffer.put(data.readBytesAt(5, 4));
// streamIdBuffer.flip();
// 
// // Ignore the reserved bit
// return streamIdBuffer.getInt() & 0x7FFFFFFF;
// }
@Override
public DataWrapper marshal(Http2Frame frame) {
    Http2FrameType frameType = frame.getFrameType();
    FrameMarshaller marshaller = dtoToMarshaller.get(frameType);
    if (marshaller == null)
        throw new IllegalArgumentException("unknown frame bean=" + frame);
    return marshaller.marshal(frame);
}
Also used : FrameMarshaller(com.webpieces.http2parser.impl.marshallers.FrameMarshaller) Http2FrameType(com.webpieces.http2.api.dto.lowlevel.lib.Http2FrameType)

Example 2 with Http2FrameType

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2FrameType in project webpieces by deanhiller.

the class Http2ParserImpl method parseBody.

private boolean parseBody(Http2MementoImpl state) {
    DataWrapper allData = state.getLeftOverData();
    FrameHeaderData headerData = state.getFrameHeaderData();
    if (headerData == null)
        throw new IllegalArgumentException("Bug, this should never be null at this point");
    int payloadLen = headerData.getPayloadLength();
    if (allData.getReadableSize() < payloadLen)
        return false;
    List<? extends DataWrapper> split = dataGen.split(allData, payloadLen);
    DataWrapper framePayloadData = split.get(0);
    AbstractHttp2Frame frame;
    Optional<Http2FrameType> optFrameType = Http2FrameType.fromId(headerData.getFrameTypeId());
    if (optFrameType.isPresent()) {
        Http2FrameType frameType = optFrameType.get();
        FrameMarshaller marshaller = dtoToMarshaller.get(frameType);
        if (marshaller == null)
            throw new IllegalArgumentException("bug, our developer forgot to add marshaller and only added the enum=" + frameType);
        frame = marshaller.unmarshal(state, framePayloadData);
    } else {
        frame = new UnknownFrame(headerData.getFlagsByte(), headerData.getFrameTypeId(), headerData.getStreamId(), framePayloadData);
    }
    int headerSize = 9;
    int size = framePayloadData.getReadableSize() + headerSize;
    // reset header data
    state.setFrameHeaderData(null);
    // subtract out read message
    state.setLeftOverData(split.get(1), -size);
    state.addParsedFrame(frame);
    return true;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) UnknownFrame(com.webpieces.http2.api.dto.lowlevel.UnknownFrame) FrameMarshaller(com.webpieces.http2parser.impl.marshallers.FrameMarshaller) Http2FrameType(com.webpieces.http2.api.dto.lowlevel.lib.Http2FrameType) AbstractHttp2Frame(com.webpieces.http2.api.dto.lowlevel.lib.AbstractHttp2Frame)

Aggregations

Http2FrameType (com.webpieces.http2.api.dto.lowlevel.lib.Http2FrameType)2 FrameMarshaller (com.webpieces.http2parser.impl.marshallers.FrameMarshaller)2 UnknownFrame (com.webpieces.http2.api.dto.lowlevel.UnknownFrame)1 AbstractHttp2Frame (com.webpieces.http2.api.dto.lowlevel.lib.AbstractHttp2Frame)1 DataWrapper (org.webpieces.data.api.DataWrapper)1