NAME

EV::WebKit::Protocol - wire codec for the EV::WebKit control protocol

DESCRIPTION

Newline-delimited JSON: one object per line, UTF-8 octets. Used by EV::WebKit::Control and EV::WebKit::Client. You do not normally touch it directly.

FUNCTIONS

encode

my $line = EV::WebKit::Protocol::encode({ i => 1, m => 'go', a => ['x'] });

Returns one newline-terminated line of UTF-8 octets.

decoder

my $dec = EV::WebKit::Protocol::decoder();
my @frames = $dec->($octets_from_the_socket);

Returns a stateful decoder. Feed it whatever the socket gave you -- a partial line, several lines, a single byte -- and it returns the frames those octets completed.

A line that is not a JSON object comes back as { _bad => $reason } rather than thrown: one client's garbage is that client's problem, not the browser's. A line longer than MAX_LINE (64 MiB) is refused outright, so a client that never sends a newline cannot make the server buffer without bound.