Package dev.relism.flash.websocket
Class WebSocketFrame
java.lang.Object
dev.relism.flash.websocket.WebSocketFrame
Zero-copy view over
WebSocketSession's read buffer.
One instance allocated per connection, reset per frame — zero steady-state allocation.
Lifetime contract: valid ONLY within the synchronous scope of
WebSocketHandler.onMessage(WebSocketSession, WebSocketFrame).
The underlying buffer is owned by WebSocketSession and will be
overwritten on the next frame read. Never retain a reference beyond the
callback; use copyPayload() when data must outlive the call.
Debug safety: buffer() is package-private to prevent
accidental cross-boundary access. External consumers must go through
copyPayload() or process in-place within the callback.
-
Field Details
-
OP_CONTINUATION
public static final byte OP_CONTINUATION- See Also:
-
OP_TEXT
public static final byte OP_TEXT- See Also:
-
OP_BINARY
public static final byte OP_BINARY- See Also:
-
OP_CLOSE
public static final byte OP_CLOSE- See Also:
-
OP_PING
public static final byte OP_PING- See Also:
-
OP_PONG
public static final byte OP_PONG- See Also:
-
-
Constructor Details
-
WebSocketFrame
public WebSocketFrame()
-
-
Method Details
-
opcode
public byte opcode() -
isFin
public boolean isFin() -
payloadOffset
public int payloadOffset() -
payloadLength
public int payloadLength() -
generation
public int generation()Returns the generation counter at the moment of this call. Store it at callback entry and compare later to detect stale retention:int gen = frame.generation(); executor.submit(() -> { assert frame.generation() == gen : "frame buffer was recycled!"; }); -
copyPayload
public byte[] copyPayload()Copies the payload into a fresh array. Allocates — O(n) in payload size. Use only when data must outlive theonMessagecallback or be handed off to another thread. For payloads > a few KB consider wrapping the result in a pooledByteBufferto avoid GC pressure.
-