Package dev.relism.flash.http2.frame
Class Http2FrameReader
java.lang.Object
dev.relism.flash.http2.frame.Http2FrameReader
Reads length-prefixed HTTP/2 frames from one connection's
BufferedByteSource. Simpler
than RequestParser by construction: HTTP/2 frames declare their length up front (the
9-byte header), so nothing is ever scanned for — Http2FrameReader only ever needs to know
"do I have N bytes yet", never "where does this end".
Buffer discipline
One growablebyte[] per connection, reused across every frame — the same
compact-before-grow discipline RequestParser's own buffer uses. A frame's declared length
is checked against Http2Limits.MAX_FRAME_SIZE_LOCAL before the buffer
length-check, not after an allocation already paid for it.
Usage
FrameHeader header = reader.readFrame();
if (header == null) { /* clean EOF between frames — connection closing *\/ }
// ... process header.buffer()[header.payloadOffset(), +header.length()) ...
reader.consumeFrame(); // MUST be called before the next readFrame()
Thread-safety
Not thread-safe — exactly one virtual thread (the connection's demux loop) ever calls this, the same invariant every other per-connection reader in this codebase assumes.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdvances past the frame last returned byreadFrame().booleanWhether a partially received frame exhausted its non-renewable absolute deadline.booleanWhether another frame may be consumed immediately without waiting for network input.Reads the next frame's header and payload, bounded byHttp2Limits.FRAME_READ_TIMEOUT_MS, and returns the reusedFrameHeaderflyweight positioned over it — ornullon a clean EOF between frames (the peer closed the connection while nothing was in flight; not an error).readFrame(long timeoutMs) Reads one frame using a caller-supplied upper bound for this frame's absolute deadline.
-
Constructor Details
-
Http2FrameReader
-
Http2FrameReader
-
-
Method Details
-
readFrame
Reads the next frame's header and payload, bounded byHttp2Limits.FRAME_READ_TIMEOUT_MS, and returns the reusedFrameHeaderflyweight positioned over it — ornullon a clean EOF between frames (the peer closed the connection while nothing was in flight; not an error).The caller MUST call
consumeFrame()exactly once after processing this frame (or deciding to discard it) and before calling this method again.- Throws:
Http2Exception- if the declared length exceedsHttp2Limits.MAX_FRAME_SIZE_LOCALEOFException- if the connection closes after a frame has already started arrivingSocketTimeoutException- ifHttp2Limits.FRAME_READ_TIMEOUT_MSelapsesIOException
-
readFrame
Reads one frame using a caller-supplied upper bound for this frame's absolute deadline.- Throws:
IOException
-
consumeFrame
public void consumeFrame()Advances past the frame last returned byreadFrame(). Zero-copy, zero-allocation. -
frameDeadlineExpired
public boolean frameDeadlineExpired()Whether a partially received frame exhausted its non-renewable absolute deadline. -
hasBufferedInput
public boolean hasBufferedInput()Whether another frame may be consumed immediately without waiting for network input.
-