APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.net.http.http3.frames

public Class FramesDecoder

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, java.util.List, .Objects, java.util.concurrent.locks.ReentrantLock, java.util.function.LongPredicate, .Supplier, jdk.internal.net.http.common.Logger, .Utils, jdk.internal.net.http.quic.streams.QuicStreamReader, jdk.internal.net.http.quic.BuffersReader, .BuffersReader.ListBuffersReader

A FramesDecoder accumulates buffers until a frame can be decoded. It also supports decoding partial frames and reading their payload incrementally.

API Note

When the frame decoder returns a partial frame, the same frame will be returned until its payload has been fully read. The caller is supposed to call readPayloadBytes() until poll() returns a different frame. At this point there will be no remaining payload bytes to read for the previous frame.
The sequence of calls:

framesDecoder.submit(buffer); while ((frame = framesDecoder.poll()) != null) { if (frame instanceof PartialFrame partial) { var nextPayloadBytes = framesDecoder.readPayloadBytes(); if (nextPayloadBytes == null || nextPayloadBytes.isEmpty()) { // no more data is available at this moment break; } // nextPayloadBytes are the next bytes for the payload // of the partial frame deliverBytes(partial, nextPayloadBytes); } else ... // got a full frame... }
framesDecoder.submit(buffer);
while ((frame = framesDecoder.poll()) != null) {
    if (frame instanceof PartialFrame partial) {
        var nextPayloadBytes = framesDecoder.readPayloadBytes();
        if (nextPayloadBytes == null || nextPayloadBytes.isEmpty()) {
             // no more data is available at this moment
             break;
        }
        // nextPayloadBytes are the next bytes for the payload
        // of the partial frame
        deliverBytes(partial, nextPayloadBytes);
    } else ...
        // got a full frame...
}
makes it possible to incrementally deliver payload bytes for a frame - since poll() will always return the same partial frame until all its payload has been read.

Field Summary

Modifier and TypeField and Description
private final Supplier<String>
private final Logger
pack-priv boolean
private final BuffersReader.ListBuffersReader
private final LongPredicate
private final ReentrantLock
pack-priv PartialFrame

Constructor Summary

AccessConstructor and Description
public
FramesDecoder(String
a debug tag for logging
dbgTag
)

A new FramesDecoder that accepts all frames.

public
FramesDecoder(String
a debug tag for logging
dbgTag
,
LongPredicate isAllowed)

A new FramesDecoder that accepts only frames authorized by the given isAllowed predicate.

public
FramesDecoder(Supplier<String>
a debug tag for logging
dbgTag
,
LongPredicate isAllowed)

A new FramesDecoder that accepts only frames authorized by the given isAllowed predicate.

Method Summary

Modifier and TypeMethod and Description
private static boolean
allAllowed(long frameType)

public boolean

Returns:

true if all buffers have been read
clean
()

Returns true if all buffers have been read.

public void
clear()

Clears any unconsumed buffers.

pack-priv String
public boolean

Returns:

true if EOF has been reached and all buffers have been read
eof
()

Returns true if EOF has been reached and all buffers have been read.

protected boolean

Returns:

true if the frame is allowed
isAllowed
(long
the frame type
frameType
)

Can be overridden by subclasses to avoid parsing a frame fully if the frame is not allowed on this stream, or according to the stream state.

public static boolean

Returns:

whether a frame of this type is allowed on a control stream.
isAllowedOnClientControlStream
(long
a frame type
frameType
)

A predicate that returns true for all frames types allowed on the client->server control stream.

public static boolean

Returns:

whether a frame of this type is allowed on a control stream.
isAllowedOnControlStream
(long
a frame type
frameType
)

A predicate that returns true for all frames types allowed on the server->client control stream.

public static boolean

Returns:

whether a frame of this type is allowed on a request/response stream.
isAllowedOnPromiseStream
(long
a frame type
frameType
)

A predicate that returns true for all frames types allowed on a push promise stream.

public static boolean

Returns:

whether a frame of this type is allowed on a request/response stream.
isAllowedOnRequestStream
(long
a frame type
frameType
)

A predicate that returns true for all frames types allowed on a request/response stream.

public Http3Frame

Returns:

an Http3Frame, possibly partial, or null if not enough bytes have been receive to decode (at least partially) a frame
poll
()

Returns an Http3Frame, possibly partial, or null if not enough bytes have been receive to decode (at least partially) a frame.

public List<ByteBuffer>

Returns:

the next payload bytes for the current partial frame, or null if no partial frame
readPayloadBytes
()

Returns the next payload bytes for the current partial frame, or null if no partial frame.

public void
submit(ByteBuffer
a new buffer from the stream
buffer
)

Submit a new buffer to this frames decoder

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dbgTagback to summary
private final Supplier<String> dbgTag
debugback to summary
private final Logger debug
eofback to summary
pack-priv boolean eof
framesReaderback to summary
private final BuffersReader.ListBuffersReader framesReader
isAllowedback to summary
private final LongPredicate isAllowed
lockback to summary
private final ReentrantLock lock
partialFrameback to summary
pack-priv PartialFrame partialFrame

Constructor Detail

FramesDecoderback to summary
public FramesDecoder(String dbgTag)

A new FramesDecoder that accepts all frames.

Parameters
dbgTag:String

a debug tag for logging

FramesDecoderback to summary
public FramesDecoder(String dbgTag, LongPredicate isAllowed)

A new FramesDecoder that accepts only frames authorized by the given isAllowed predicate. If a frame is not allowed, a MalformedFrame is returned.

Parameters
dbgTag:String

a debug tag for logging

FramesDecoderback to summary
public FramesDecoder(Supplier<String> dbgTag, LongPredicate isAllowed)

A new FramesDecoder that accepts only frames authorized by the given isAllowed predicate. If a frame is not allowed, a MalformedFrame is returned.

Parameters
dbgTag:Supplier<String>

a debug tag for logging

Method Detail

allAllowedback to summary
private static boolean allAllowed(long frameType)
cleanback to summary
public boolean clean()

Returns true if all buffers have been read.

Returns:boolean

true if all buffers have been read

clearback to summary
public void clear()

Clears any unconsumed buffers.

dbgTagback to summary
pack-priv String dbgTag()
eofback to summary
public boolean eof()

Returns true if EOF has been reached and all buffers have been read.

Returns:boolean

true if EOF has been reached and all buffers have been read

isAllowedback to summary
protected boolean isAllowed(long frameType)

Can be overridden by subclasses to avoid parsing a frame fully if the frame is not allowed on this stream, or according to the stream state.

Implementation Specification

This method delegates to the predicate given at construction time. If no predicate was given this method returns true.

Parameters
frameType:long

the frame type

Returns:boolean

true if the frame is allowed

isAllowedOnClientControlStreamback to summary
public static boolean isAllowedOnClientControlStream(long frameType)

A predicate that returns true for all frames types allowed on the client->server control stream.

Parameters
frameType:long

a frame type

Returns:boolean

whether a frame of this type is allowed on a control stream.

isAllowedOnControlStreamback to summary
public static boolean isAllowedOnControlStream(long frameType)

A predicate that returns true for all frames types allowed on the server->client control stream.

Parameters
frameType:long

a frame type

Returns:boolean

whether a frame of this type is allowed on a control stream.

isAllowedOnPromiseStreamback to summary
public static boolean isAllowedOnPromiseStream(long frameType)

A predicate that returns true for all frames types allowed on a push promise stream.

Parameters
frameType:long

a frame type

Returns:boolean

whether a frame of this type is allowed on a request/response stream.

isAllowedOnRequestStreamback to summary
public static boolean isAllowedOnRequestStream(long frameType)

A predicate that returns true for all frames types allowed on a request/response stream.

Parameters
frameType:long

a frame type

Returns:boolean

whether a frame of this type is allowed on a request/response stream.

pollback to summary
public Http3Frame poll()

Returns an Http3Frame, possibly partial, or null if not enough bytes have been receive to decode (at least partially) a frame. If a frame is illegal or not allowed, a MalformedFrame is returned. The caller is supposed to clear all data and proceed to close the connection in that case.

Returns:Http3Frame

an Http3Frame, possibly partial, or null if not enough bytes have been receive to decode (at least partially) a frame

readPayloadBytesback to summary
public List<ByteBuffer> readPayloadBytes()

Returns the next payload bytes for the current partial frame, or null if no partial frame. If EOF has been reached (EOF was submitted, and all buffers have been read, the returned list will contain EOF

Returns:List<ByteBuffer>

the next payload bytes for the current partial frame, or null if no partial frame

submitback to summary
public void submit(ByteBuffer buffer)

Submit a new buffer to this frames decoder

Parameters
buffer:ByteBuffer

a new buffer from the stream