Class FrameDecoder

java.lang.Object
io.github.mahmoudimus.quic.frame.FrameDecoder

public final class FrameDecoder extends Object
Decodes the frames of a decrypted packet payload. Every malformed frame is a FrameException with FRAME_ENCODING_ERROR (RFC 9000 section 12.4), except a frame in a packet type that does not allow it, a frame type in a longer encoding than needed, and an empty payload, which are PROTOCOL_VIOLATIONs. Nothing else is thrown for any input.

Decoded frames that carry bytes are views of the payload buffer. All methods are static and thread-safe as long as the buffer is not shared.

  • Method Details

    • decodeAll

      public static List<Frame> decodeAll(ByteBuffer payload, PacketType packetType) throws FrameException
      Decodes every frame of a packet payload, checking each against the packet type.
      Parameters:
      payload - the plaintext payload between its position and limit; its position moves to the limit
      packetType - the type of the packet the payload came in
      Returns:
      the frames, with each run of PADDING as one Frame.Padding
      Throws:
      FrameException - if the payload is empty or a frame is malformed or not allowed
    • decode

      public static Frame decode(ByteBuffer in) throws FrameException
      Decodes one frame at the buffer's position.
      Parameters:
      in - the payload; its position moves past the frame
      Returns:
      the frame; a run of PADDING bytes is one Frame.Padding
      Throws:
      FrameException - if the frame is malformed, truncated or of an unknown type