use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class MockHttp2Channel method write.
public void write(Http2Msg msg) {
if (listener == null)
throw new IllegalStateException("Not connected so we cannot write back");
DataWrapper data = parser.marshal(marshalState, msg);
byte[] bytes = data.createByteArray();
if (bytes.length == 0)
throw new IllegalArgumentException("how do you marshal to 0 bytes...WTF");
ByteBuffer buf = ByteBuffer.wrap(bytes);
listener.incomingData(this, buf);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class MockHttp2Channel method processData.
@SuppressWarnings("unchecked")
private CompletableFuture<Channel> processData(ByteBuffer b) {
DataWrapper data = dataGen.wrapByteBuffer(b);
parser.unmarshal(unmarshalState, data);
List<Http2Msg> parsedFrames = unmarshalState.getParsedFrames();
return (CompletableFuture<Channel>) super.calledMethod(Method.INCOMING_FRAME, parsedFrames);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Level3ClntOutgoingSyncro method sendInitializationToSocket.
public CompletableFuture<Void> sendInitializationToSocket() {
//important, this forces the engine to a virtual single thread(each engine/socket has one virtual thread)
//this makes it very easy not to have bugs AND very easy to test AND for better throughput, you can
//just connect more sockets
log.info("sending preface");
DataWrapper prefaceData = dataGen.wrapByteArray(preface);
return finalLayer.sendPreface(prefaceData).thenCompose(v -> super.sendSettingsToSocket());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Preface method verify.
public void verify() {
buffer.flip();
DataWrapper data = dataGen.wrapByteBuffer(buffer);
String content = data.createStringFromUtf8(0, data.getReadableSize());
if (!"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".equals(content))
throw new IllegalStateException("preface incorrect=" + content);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class PushPromiseMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
PushPromiseFrame castFrame = (PushPromiseFrame) frame;
int originalStreamId = castFrame.getPromisedStreamId();
int streamId = originalStreamId & 0x7FFFFFFF;
if (streamId != originalStreamId)
throw new RuntimeException("your promisedStreamId is too large per spec. frame=" + frame);
int paddingSize = castFrame.getPadding().getReadableSize();
byte value = 0x0;
if (castFrame.isEndHeaders())
value |= 0x4;
if (paddingSize > 0)
value |= 0x8;
ByteBuffer prelude = bufferPool.nextBuffer(4);
prelude.putInt(castFrame.getPromisedStreamId());
prelude.flip();
DataWrapper headersDW = castFrame.getHeaderFragment();
DataWrapper finalDW = dataGen.chainDataWrappers(dataGen.wrapByteBuffer(prelude), headersDW);
DataWrapper payload = PaddingUtil.padDataIfNeeded(finalDW, castFrame.getPadding());
return super.marshalFrame(frame, value, payload);
}
Aggregations