Package io.github.mahmoudimus.quic
Class ConnectionId
java.lang.Object
io.github.mahmoudimus.quic.ConnectionId
- All Implemented Interfaces:
Comparable<ConnectionId>
A QUIC connection ID (RFC 9000 section 5.1): 0 to 20 opaque bytes with value semantics.
Instances are immutable and thread-safe; the bytes are copied in and out.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ConnectionIdThe zero-length connection ID.static final intThe longest connection ID QUIC version 1 and 2 allow, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionintOrders by length, then by unsigned bytes.booleanbyteget(int index) One byte of the ID.inthashCode()booleanisEmpty()Whether this is the zero-length connection ID.intlength()The length in bytes.static ConnectionIdof(byte... bytes) A connection ID with a copy of some bytes.static ConnectionIdof(byte[] bytes, int offset, int length) A connection ID with a copy of part of an array.static ConnectionIdA random connection ID.static ConnectionIdread(ByteBuffer in, int length) Reads a connection ID of known length at the buffer's position.byte[]A copy of the bytes.toString()The bytes in lowercase hexadecimal.intwriteTo(byte[] out, int offset) Writes the bytes into an array, without a length prefix.voidwriteTo(ByteBuffer out) Writes the bytes, without a length prefix.
-
Field Details
-
MAX_LENGTH
public static final int MAX_LENGTHThe longest connection ID QUIC version 1 and 2 allow, in bytes.- See Also:
-
EMPTY
The zero-length connection ID.
-
-
Method Details
-
of
A connection ID with a copy of some bytes.- Parameters:
bytes- 0 toMAX_LENGTHbytes- Returns:
- the connection ID
- Throws:
IllegalArgumentException- if there are more thanMAX_LENGTHbytes
-
of
A connection ID with a copy of part of an array.- Parameters:
bytes- the arrayoffset- the first bytelength- the length, 0 toMAX_LENGTH- Returns:
- the connection ID
- Throws:
IllegalArgumentException- if the length is out of rangeIndexOutOfBoundsException- if the range is outside the array
-
read
Reads a connection ID of known length at the buffer's position.- Parameters:
in- the buffer; its position moves past the connection IDlength- the length, 0 toMAX_LENGTH- Returns:
- the connection ID
- Throws:
IllegalArgumentException- if the length is out of rangeBufferUnderflowException- if fewer thanlengthbytes remain
-
random
A random connection ID. Use aSecureRandomfor IDs sent on the wire.- Parameters:
random- the source of randomnesslength- the length, 0 toMAX_LENGTH- Returns:
- the connection ID
- Throws:
IllegalArgumentException- if the length is out of range
-
length
public int length()The length in bytes.- Returns:
- 0 to
MAX_LENGTH
-
isEmpty
public boolean isEmpty()Whether this is the zero-length connection ID.- Returns:
- true if the length is zero
-
get
public byte get(int index) One byte of the ID.- Parameters:
index- the index, belowlength()- Returns:
- the byte
-
toByteArray
public byte[] toByteArray()A copy of the bytes.- Returns:
- a new array
-
writeTo
Writes the bytes, without a length prefix.- Parameters:
out- the buffer, written at its position
-
writeTo
public int writeTo(byte[] out, int offset) Writes the bytes into an array, without a length prefix.- Parameters:
out- the arrayoffset- where to write- Returns:
- the offset just past the bytes
-
equals
-
hashCode
public int hashCode() -
compareTo
Orders by length, then by unsigned bytes.- Specified by:
compareToin interfaceComparable<ConnectionId>
-
toString
The bytes in lowercase hexadecimal.
-