public static function decode_websocket_events($body)
    {
        $out = array();
        $start = 0;
        while ($start < strlen($body)) {
            $at = strpos($body, "\r\n", $start);
            if ($at === false) {
                throw new \RuntimeException('bad format');
            }
            $typeline = substr($body, $start, $at - $start);
            $start = $at + 2;
            $at = strpos($typeline, ' ');
            $e = null;
            if (!($at === false)) {
                $etype = substr($typeline, 0, $at);
                $clen = intval('0x' . substr($typeline, $at + 1), 16);
                $content = substr($body, $start, $clen);
                $start += $clen + 2;
                $e = new WebSocketEvent($etype, $content);
            } else {
                $e = new WebSocketEvent($typeline);
            }
            $out[] = $e;
        }
        return $out;
    }