APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http.qpack

public final Class Decoder

extends Object
Class Inheritance
Imports
jdk.internal.net.http.common.Utils, jdk.internal.net.http.http3.ConnectionSettings, jdk.internal.net.http.http3.streams.QueuingStreamPair, .UniStreamPair, jdk.internal.net.http.qpack.QPACK.QPACKErrorHandler, .QPACK.StreamPairSupplier, jdk.internal.net.http.qpack.readers.EncoderInstructionsReader, .HeaderFrameReader, jdk.internal.net.http.qpack.writers.DecoderInstructionsWriter, jdk.internal.net.http.quic.streams.QuicStreamReader, java.io.IOException, java.net.ProtocolException, java.nio.ByteBuffer, java.util.concurrent.atomic.AtomicLong, java.util.concurrent.locks.ReentrantLock

Decodes headers from their binary representation.

Typical lifecycle looks like this:

new Decoder (configure(ConnectionSettings) called once from our HTTP/3 settings decodeHeader

Decoder does not require a complete header block in a single ByteBuffer. The header block can be spread across many buffers of any size and decoded one-by-one the way it makes most sense for the user. This way also allows not to limit the size of the header block.

Headers are delivered to the callback as soon as they become decoded. Using the callback also gives the user freedom to decide how headers are processed. The callback does not limit the number of headers decoded during single decoding operation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final ReentrantLock
private long
private final AtomicLong
private final AtomicLong
private static final AtomicLong
private final QueuingStreamPair
private final DynamicTable
private final EncoderInstructionsReader
private final QPACK.Logger
private static final long
private volatile long
private volatile long
private final QPACK.QPACKErrorHandler

Constructor Summary

AccessConstructor and Description
public
Decoder(QPACK.StreamPairSupplier streams, QPACK.QPACKErrorHandler errorHandler)

Constructs a Decoder with zero initial capacity of the dynamic table.

Method Summary

Modifier and TypeMethod and Description
public void
ackSection(long
stream ID associated with the field section's
streamId
,
HeaderFrameReader
header frame reader used to read the field line section
headerFrameReader
)

Submit "Section Acknowledgment" instruction to the decoder stream.

public void
public void
cancelStream(long streamId)

public void
configure(ConnectionSettings
connection settings
ourSettings
)

Configures maximum capacity of the decoder's dynamic table based on connection settings of the HTTP client, also configures the number of allowed blocked streams.

public void
decodeHeader(ByteBuffer
the chunk of the header block, may be empty
headerBlock
,
boolean
true if the chunk is the final (or the only one) in the sequence
endOfHeaderBlock
,
HeaderFrameReader
the stateful header frame reader
headerFrameReader
)

Decodes a header block from the given buffer to the given callback.

public QueuingStreamPair
pack-priv void
public HeaderFrameReader

Returns:

a new HeaderFrameReader that will hold the decoding state for a new request/response stream
newHeaderFrameReader
(DecodingCallback decodingCallback)

Returns a new HeaderFrameReader that will hold the decoding state for a new request/response stream.

private void
processEncoderInstruction(ByteBuffer buffer)

This method is invoked when the decoder's stream reader has data available for reading.

public void
private void
submitDecoderInstruction(DecoderInstructionsWriter decoderInstructionsWriter, int size)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ackInsertCountLockback to summary
private final ReentrantLock ackInsertCountLock
acknowledgedInsertsCountback to summary
private long acknowledgedInsertsCount
blockedStreamsCounterback to summary
private final AtomicLong blockedStreamsCounter
concurrentDynamicTableInsertionsback to summary
private final AtomicLong concurrentDynamicTableInsertions
DECODERS_IDSback to summary
private static final AtomicLong DECODERS_IDS
decoderStreamPairback to summary
private final QueuingStreamPair decoderStreamPair
dynamicTableback to summary
private final DynamicTable dynamicTable
encoderInstructionsReaderback to summary
private final EncoderInstructionsReader encoderInstructionsReader
loggerback to summary
private final QPACK.Logger logger
MAX_LITERAL_WITH_INDEXINGback to summary
private static final long MAX_LITERAL_WITH_INDEXING
maxBlockedStreamsback to summary
private volatile long maxBlockedStreams
maxFieldSectionSizeback to summary
private volatile long maxFieldSectionSize
qpackErrorHandlerback to summary
private final QPACK.QPACKErrorHandler qpackErrorHandler

Constructor Detail

Decoderback to summary
public Decoder(QPACK.StreamPairSupplier streams, QPACK.QPACKErrorHandler errorHandler)

Constructs a Decoder with zero initial capacity of the dynamic table.

Dynamic table capacity values has to be agreed between decoder and encoder out-of-band, e.g. by a protocol that uses QPACK.

Maximum dynamic table capacity is determined by the value of SETTINGS_QPACK_MAX_TABLE_CAPACITY HTTP/3 setting sent by the decoder side (see 3.2.3. Maximum Dynamic Table Capacity).

An encoder informs the decoder of a change to the dynamic table capacity using the "Set Dynamic Table Capacity" instruction (see 4.3.1. Set Dynamic Table Capacity)

See Also
Decoder#configure(ConnectionSettings)

Method Detail

ackSectionback to summary
public void ackSection(long streamId, HeaderFrameReader headerFrameReader)

Submit "Section Acknowledgment" instruction to the decoder stream. A field line section needs to be acknowledged after completion of section decoding.

Parameters
streamId:long

stream ID associated with the field section's

headerFrameReader:HeaderFrameReader

header frame reader used to read the field line section

ackTableInsertionsback to summary
public void ackTableInsertions()
cancelStreamback to summary
public void cancelStream(long streamId)
configureback to summary
public void configure(ConnectionSettings ourSettings)

Configures maximum capacity of the decoder's dynamic table based on connection settings of the HTTP client, also configures the number of allowed blocked streams. The decoder's dynamic table capacity can only be changed via encoder instructions callback.

Parameters
ourSettings:ConnectionSettings

connection settings

decodeHeaderback to summary
public void decodeHeader(ByteBuffer headerBlock, boolean endOfHeaderBlock, HeaderFrameReader headerFrameReader)

Decodes a header block from the given buffer to the given callback.

Suppose a header block is represented by a sequence of ByteBuffers in the form of Iterator<ByteBuffer>. And the consumer of decoded headers is represented by the callback registered within the provided headerFrameReader. Then to decode the header block, the following approach might be used:

HeaderFrameReader headerFrameReader = newHeaderFrameReader(decodingCallback); while (buffers.hasNext()) { ByteBuffer input = buffers.next(); decoder.decodeHeader(input, !buffers.hasNext(), headerFrameReader); }
HeaderFrameReader headerFrameReader =
     newHeaderFrameReader(decodingCallback);
while (buffers.hasNext()) {
    ByteBuffer input = buffers.next();
    decoder.decodeHeader(input, !buffers.hasNext(), headerFrameReader);
}

The decoder reads as much as possible of the header block from the given buffer, starting at the buffer's position, and increments its position to reflect the bytes read. The buffer's mark and limit will not be modified.

Once the method is invoked with endOfHeaderBlock == true, the current header block is deemed ended, and inconsistencies, if any, are reported immediately via a callback registered within the headerFrameReader instance.

Each callback method is called only after the implementation has processed the corresponding bytes. If the bytes revealed a decoding error it is reported via a callback registered within the headerFrameReader instance.

API Note

The method asks for endOfHeaderBlock flag instead of returning it for two reasons. The first one is that the user of the decoder always knows which chunk is the last. The second one is to throw the most detailed exception possible, which might be useful for diagnosing issues.

Implementation Note

This implementation is not atomic in respect to decoding errors. In other words, if the decoding operation has thrown a decoding error, the decoder is no longer usable.

Parameters
headerBlock:ByteBuffer

the chunk of the header block, may be empty

endOfHeaderBlock:boolean

true if the chunk is the final (or the only one) in the sequence

headerFrameReader:HeaderFrameReader

the stateful header frame reader

Exceptions
NullPointerException:
if either headerBlock or headerFrameReader are null
decoderStreamsback to summary
public QueuingStreamPair decoderStreams()
incrementAndCheckDynamicTableInsertsCountback to summary
pack-priv void incrementAndCheckDynamicTableInsertsCount()
newHeaderFrameReaderback to summary
public HeaderFrameReader newHeaderFrameReader(DecodingCallback decodingCallback)

Returns a new HeaderFrameReader that will hold the decoding state for a new request/response stream.

Returns:HeaderFrameReader

a new HeaderFrameReader that will hold the decoding state for a new request/response stream

processEncoderInstructionback to summary
private void processEncoderInstruction(ByteBuffer buffer)

This method is invoked when the decoder's stream reader has data available for reading.

resetInsertionsCounterback to summary
public void resetInsertionsCounter()
submitDecoderInstructionback to summary
private void submitDecoderInstruction(DecoderInstructionsWriter decoderInstructionsWriter, int size)
jdk.internal.net.http.qpack back to summary

private Class Decoder.DecoderTableCallback

extends Object
implements Callback
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.qpack.readers.EncoderInstructionsReader.Callback

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
public void
public void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DecoderTableCallbackback to summary
private DecoderTableCallback()

Method Detail

ensureInstructionsAllowedback to summary
private void ensureInstructionsAllowed()
onCapacityUpdateback to summary
public void onCapacityUpdate(long capacity)

Implements jdk.internal.net.http.qpack.readers.EncoderInstructionsReader.Callback.onCapacityUpdate.

Annotations
@Override
onDuplicateback to summary
public void onDuplicate(long l)

Implements jdk.internal.net.http.qpack.readers.EncoderInstructionsReader.Callback.onDuplicate.

Annotations
@Override
onInsertback to summary
public void onInsert(String name, String value)

Implements jdk.internal.net.http.qpack.readers.EncoderInstructionsReader.Callback.onInsert.

Annotations
@Override
onInsertIndexedNameback to summary
public void onInsertIndexedName(boolean indexInStaticTable, long nameIndex, String valueString)

Implements jdk.internal.net.http.qpack.readers.EncoderInstructionsReader.Callback.onInsertIndexedName.

Annotations
@Override