The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Protocol::WebSocket::Fast::Frame - WebSocket Frame class

DESCRIPTION

The class represents a frame received via WebSocket protocol.

The Frame object cannot be instantiated direcly, it can be accessed via Protocol::WebSocket::Fast::FrameIterator or Protocol::WebSocket::Fast::Parser.

The Frame object is read-only, i.e. all provided methods are just getters.

METHODS

error()

Returns undef if there were no errors during parsing the frame.

Otherwise returns an XS::ErrorCode object which represents Perl API for convenient C++ std::error_code subsystem. Possible errors are described in Protocol::WebSocket::Fast::Error and Protocol::HTTP::Error.

    my $frame = $frame_iterator->next;
    if ($frame->error) {
        if    ($frame->error == Protocol::WebSocket::Fast::Error::invalid_opcode) { ... }
        elsif ($frame->error == Protocol::WebSocket::Fast::Error::max_frame_size) { ... }
        else  { ... }
    }

opcode()

The opcode value for the current frame

See constants in Protocol::WebSocket::Fast.

is_control()

True if the frame is a control frame

final()

True if the frame is final

payload_length()

Returns frame payload length, i.e. size of transferred bytes over network. Might not match the size of actual payload if it was compressed.

payload()

Returns payload as a string.

Performance note: as the underhood the payload can be transferred over network in different fragments, it might be uneffective to concantenate all pieces every time on payload access; in other words it is recommended to cache the method.

close_code()

If this frame is a close frame, returns its close code, see Protocol::WebSocket::Fast for constants.

close_message()

If this frame is a close frame, returns its message.

SEE ALSO

Protocol::WebSocket::Fast

Protocol::WebSocket::Fast::FrameIterator

Protocol::WebSocket::Fast::Message

Protocol::WebSocket::Fast::Parser

rfc6455