Represents the decoded wire form: header fields extracted and
payload already de-masked (clients unmask on receive).
Owns the payload buffer.
Fields:
fin: True if this is the final fragment of a message.
rsv1: Extension bit RSV1 (must be False unless extension negotiated).
opcode: Frame opcode (see WsOpcode.*).
masked: True if the payload was masked on the wire (client→server only).
payload: The unmasked payload bytes.
Example:
var frame = WsFrame.text("hello")
var wire = frame.encode(mask=True) # client sending to server
text
def text(msg: String) -> Self
Create a text (UTF-8) frame.
- Args
msg: The UTF-8 text payload.
decode_one
def decode_one(data: Span[UInt8], allow_rsv1: Bool = False, max_payload: Int = Int(16777216)) -> _DecodeResult
Parse one frame from data.
- Args
data: Raw bytes from the socket (may contain more than one frame).allow_rsv1: Accept a set RSV1 bit. Pass True only on a
connection that negotiated an extension defining it
(permessage-deflate, RFC 7692); the default rejects it
per RFC 6455 sec 5.2, which requires a receiver to fail
the connection on a reserved bit no negotiated extension
gives meaning to.max_payload: Largest payload accepted, checked against the
declared length as soon as it is parsed, before the
payload has arrived.
Raises WsProtocolError: If the frame violates RFC 6455 (bad RSV bits,
a reserved opcode, fragmented control frame,
etc.).
Error: If data is too short to contain a complete frame.
text_payload
def text_payload(self) -> String
Decode the payload as a UTF-8 string with validation.
Validates that the payload is well-formed UTF-8 per RFC 6455 §8.1.
Raises WsProtocolError on invalid sequences.
Raises WsProtocolError: If the payload contains invalid UTF-8.