APIdia Launch Partner
Top Description Constructors Methods
jdk.internal.net.http.quic.packets

public Class QuicPacketNumbers

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer

QUIC packet number encoding/decoding routines.
External Specification
https://www.rfc-editor.org/info/rfc9000

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the number of bytes required to encode the packet
computePacketNumberLength
(long
the full packet number
fullPN
,
long
the largest ACK'd packet, or -1 if none so far
largestAcked
)

Returns the number of bytes needed to encode a packet number given the full packet number and the largest ACK'd packet.

public static long

Returns:

the decoded packet number
decodePacketNumber
(long
the largest packet number that has been successfully processed in the current packet number space
largestPN
,
ByteBuffer
a ByteBuffer containing the value of the Packet Number field
buf
,
int
the number of bytes indicated by the Packet Number Length field
pnNBytes
)

Decode the packet numbers against the largest ACK'd packet after header protection has been removed.

public static byte[]

Returns:

byte array containing fullPN
encodePacketNumber
(long
the full packet number
fullPN
,
long
the largest ACK'd packet, or -1 if none so far
largestAcked
)

Encode the full packet number against the largest ACK'd packet.

public static byte[]

Returns:

byte array containing fullPN
truncatePacketNumber
(long
the full packet number
fullPN
,
int
the number of bytes in which to encode the packet number
numBytes
)

Truncate the full packet number to fill into numBytes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

QuicPacketNumbersback to summary
public QuicPacketNumbers()

Method Detail

computePacketNumberLengthback to summary
public static int computePacketNumberLength(long fullPN, long largestAcked)

Returns the number of bytes needed to encode a packet number given the full packet number and the largest ACK'd packet.

Parameters
fullPN:long

the full packet number

largestAcked:long

the largest ACK'd packet, or -1 if none so far

Returns:int

the number of bytes required to encode the packet

Exceptions
IllegalArgumentException:
if number can't represented in 4 bytes
decodePacketNumberback to summary
public static long decodePacketNumber(long largestPN, ByteBuffer buf, int pnNBytes)

Decode the packet numbers against the largest ACK'd packet after header protection has been removed. Follows the algorithm outlined in RFC 9000, Appendix A.3

Parameters
largestPN:long

the largest packet number that has been successfully processed in the current packet number space

buf:ByteBuffer

a ByteBuffer containing the value of the Packet Number field

pnNBytes:int

the number of bytes indicated by the Packet Number Length field

Returns:long

the decoded packet number

Exceptions
BufferUnderflowException:
if there is not enough data in the buffer
encodePacketNumberback to summary
public static byte[] encodePacketNumber(long fullPN, long largestAcked)

Encode the full packet number against the largest ACK'd packet. Follows the algorithm outlined in RFC 9000. Appendix A.2

Parameters
fullPN:long

the full packet number

largestAcked:long

the largest ACK'd packet, or -1 if none so far

Returns:byte[]

byte array containing fullPN

Exceptions
IllegalArgumentException:
if number can't be represented in 4 bytes
truncatePacketNumberback to summary
public static byte[] truncatePacketNumber(long fullPN, int numBytes)

Truncate the full packet number to fill into numBytes. Follows the algorithm outlined in RFC 9000, Appendix A.2

API Note

numBytes should have been computed using computePacketNumberLength(long, long)

Parameters
fullPN:long

the full packet number

numBytes:int

the number of bytes in which to encode the packet number

Returns:byte[]

byte array containing fullPN

Exceptions
IllegalArgumentException:
if numBytes is out of range