use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Requests method createData.
public static DataFrame createData(int streamId) {
DataFrame data = new DataFrame(streamId, true);
DataWrapper wrapByteArray = dataGen.wrapByteArray(new byte[] { 2, 3 });
data.setData(wrapByteArray);
return data;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Level6RemoteFlowControl method splitDataFrame.
private List<DataTry> splitDataFrame(DataTry dataTry, long lengthToSend) {
if (lengthToSend > Integer.MAX_VALUE)
throw new IllegalStateException("bug, length to send should not be this large(per spec)=" + lengthToSend);
int len = (int) lengthToSend;
DataFrame dataFrame = dataTry.getDataFrame();
DataWrapper data = dataFrame.getData();
if (dataFrame.getPadding().getReadableSize() > 0)
throw new UnsupportedOperationException("Splitting padding under these conditions would be" + " quite difficult so we skipped it. perhaps stop using padding or" + " modify this code but some padding would have to go in one" + " DataFrame and the rest in the next as the window size is not large enough");
List<? extends DataWrapper> split = dataGen.split(data, len);
DataFrame dF1 = new DataFrame();
dF1.setData(split.get(0));
DataFrame dF2 = new DataFrame();
dF2.setData(split.get(1));
List<DataTry> tuple = new ArrayList<>();
tuple.add(new DataTry(dataTry.getStream(), dF1, null, dataTry.isWasQueuedBefore()));
tuple.add(new DataTry(dataTry.getStream(), dF2, dataTry.getFuture(), dataTry.isWasQueuedBefore()));
return tuple;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Level7MarshalAndPing method sendFrameToSocket.
public CompletableFuture<Void> sendFrameToSocket(Http2Msg msg) {
log.info(key + "sending frame down to socket(from client)=\n" + msg);
DataWrapper data = parser.marshal(marshalState, msg);
ByteBuffer buffer = ByteBuffer.wrap(data.createByteArray());
return sendToSocket(buffer);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Level7MarshalAndPing method goAway.
public CompletableFuture<Void> goAway(ShutdownConnection shutdown) {
CancelReasonCode reason = shutdown.getReasonCode();
byte[] bytes = shutdown.getReason().getBytes(StandardCharsets.UTF_8);
DataWrapper debug = dataGen.wrapByteArray(bytes);
GoAwayFrame frame = new GoAwayFrame();
frame.setDebugData(debug);
frame.setKnownErrorCode(reason.getErrorCode());
CompletableFuture<Void> future1 = sendControlDataToSocket(frame);
finalLayer.closeSocket(shutdown);
return future1;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class HeaderEncoding method createHeaderFrames.
private List<Http2Frame> createHeaderFrames(HasHeaderFragment initialFrame, List<Http2Header> headers, Encoder encoder, long maxFrameSize) {
int maxSize = (int) maxFrameSize;
if (maxFrameSize > Integer.MAX_VALUE)
throw new IllegalStateException("max frame size too large for this hpack library");
List<Http2Frame> headerFrames = new LinkedList<>();
DataWrapper serializedHeaders = serializeHeaders(encoder, headers);
HasHeaderFragment currentFrame = initialFrame;
HasHeaderFragment lastFrame = currentFrame;
DataWrapper dataLeftOver = serializedHeaders;
while (dataLeftOver.getReadableSize() > 0) {
lastFrame = currentFrame;
int splitSize = Math.min(dataLeftOver.getReadableSize(), maxSize);
List<? extends DataWrapper> split = dataGen.split(dataLeftOver, splitSize);
DataWrapper fragment = split.get(0);
currentFrame.setHeaderFragment(fragment);
headerFrames.add(currentFrame);
currentFrame = new ContinuationFrame();
currentFrame.setStreamId(initialFrame.getStreamId());
dataLeftOver = split.get(1);
}
//last frame is currentFrame so set end header
lastFrame.setEndHeaders(true);
return headerFrames;
}
Aggregations