use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class HpackParserImpl method combineAndSendHeadersToClient.
private void combineAndSendHeadersToClient(UnmarshalStateImpl state) {
List<HasHeaderFragment> hasHeaderFragmentList = state.getHeadersToCombine();
// Now we set the full header list on the first frame and just return that
HasHeaderFragment firstFrame = hasHeaderFragmentList.get(0);
DataWrapper allSerializedHeaders = dataGen.emptyWrapper();
for (HasHeaderFragment iterFrame : hasHeaderFragmentList) {
allSerializedHeaders = dataGen.chainDataWrappers(allSerializedHeaders, iterFrame.getHeaderFragment());
}
Map<Http2HeaderName, Http2Header> knownHeaders = new HashMap<>();
List<Http2Header> headers = decoding.decode(state, allSerializedHeaders, firstFrame.getStreamId(), header -> knownHeaders.put(header.getKnownName(), header));
if (firstFrame instanceof HeadersFrame) {
HeadersFrame f = (HeadersFrame) firstFrame;
Http2Headers fullHeaders = createCorrectType(knownHeaders, headers, state.getLogId(), f.getStreamId());
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPriorityDetails(f.getPriorityDetails());
fullHeaders.setEndOfStream(f.isEndOfStream());
state.getParsedFrames().add(fullHeaders);
} else if (firstFrame instanceof PushPromiseFrame) {
PushPromiseFrame f = (PushPromiseFrame) firstFrame;
Http2Push fullHeaders = new Http2Push(headers);
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
state.getParsedFrames().add(fullHeaders);
}
hasHeaderFragmentList.clear();
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class PaddingUtil method padDataIfNeeded.
public static DataWrapper padDataIfNeeded(DataWrapper data, DataWrapper padding) {
if (padding.getReadableSize() > 0) {
byte[] length = { (byte) padding.getReadableSize() };
DataWrapper lengthDW = dataGen.wrapByteArray(length);
return dataGen.chainDataWrappers(dataGen.chainDataWrappers(lengthDW, data), padding);
} else
return data;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class DataWrapperGeneratorImpl method chainDataWrappers.
@Override
public DataWrapper chainDataWrappers(DataWrapper firstData, ByteBuffer... secondData) {
DataWrapper wrapper = firstData;
for (ByteBuffer buffer : secondData) {
DataWrapper second = wrapByteBuffer(buffer);
wrapper = chainDataWrappers(wrapper, second);
}
return wrapper;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class ChainedDataWrapper method readByteAt.
@Override
public byte readByteAt(int i) {
int j = i;
for (DataWrapper wrapper : wrappers) {
int size = wrapper.getReadableSize();
if (j < size) {
return wrapper.readByteAt(j);
}
j = j - size;
}
throw new IndexOutOfBoundsException("i=" + i + " is out of bounds of size=" + getReadableSize());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class ChainedDataWrapper method createStringFrom.
@Override
public String createStringFrom(int initialOffset, int length, Charset charSet) {
if (length == 0)
return "";
String result = "";
int lengthLeftToRead = length;
int offset = initialOffset;
for (DataWrapper wrapper : wrappers) {
int size = wrapper.getReadableSize();
if (offset < size) {
if (offset + lengthLeftToRead <= size) {
result += wrapper.createStringFrom(offset, lengthLeftToRead, charSet);
return result;
}
int leftInBuffer = size - offset;
result += wrapper.createStringFrom(offset, leftInBuffer, charSet);
//since we read in this data, offset for next datawrapper is 0
offset = 0;
lengthLeftToRead -= leftInBuffer;
} else {
offset -= size;
}
}
throw new IndexOutOfBoundsException("offset=" + offset + " length=" + length + " is larger than size=" + getReadableSize());
}
Aggregations