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;
}
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);
}
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);
}
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;
}
}
}
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);
}
Aggregations