\href{https://travis-ci.org/socketio/engine.io-parser}{\texttt{ }} \href{https://npmjs.com/package/engine.io-parser}{\texttt{ }}

This is the Java\+Script parser for the engine.\+io protocol encoding, shared by both \href{https://github.com/socketio/engine.io-client}{\texttt{ engine.\+io-\/client}} and \href{https://github.com/socketio/engine.io}{\texttt{ engine.\+io}}.\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8713}{}\doxysection{How to use}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8713}
\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8714}{}\doxysubsection{Standalone}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8714}
The parser can encode/decode packets, payloads, and payloads as binary with the following methods\+: {\ttfamily encode\+Packet}, {\ttfamily decode\+Packet}, {\ttfamily encode\+Payload}, {\ttfamily decode\+Payload}, {\ttfamily encode\+Payload\+As\+Binary}, {\ttfamily decode\+Payload\+As\+Binary}.

The browser-\/side parser also includes {\ttfamily encode\+Payload\+As\+Array\+Buffer} and {\ttfamily encode\+Payload\+As\+Blob}.

Example\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var parser = require('engine.io-\/parser');}
\DoxyCodeLine{}
\DoxyCodeLine{var data = new Buffer(5);}
\DoxyCodeLine{for (var i = 0; i < data.length; i++) \{ data[i] = i; \}}
\DoxyCodeLine{}
\DoxyCodeLine{parser.encodePacket(\{ type: 'message', data: data \}, function(encoded) \{}
\DoxyCodeLine{  var decodedData = parser.decodePacket(encoded); // \{ type: 'message', data: data \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8715}{}\doxysubsection{With browserify}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8715}
Engine.\+IO Parser is a commonjs module, which means you can include it by using {\ttfamily require} on the browser and package using \href{http://browserify.org/}{\texttt{ browserify}}\+:


\begin{DoxyEnumerate}
\item install the parser package

\`{}\`{}\`{}shell npm install engine.\+io-\/parser \`{}\`{}\`{}
\end{DoxyEnumerate}
\begin{DoxyEnumerate}
\item write your app code

\`{}\`{}`js var parser = require(\textquotesingle{}engine.\+io-\/parser');

var test\+Buffer = new Int8\+Array(10); for (var i = 0; i $<$ test\+Buffer.\+length; i++) test\+Buffer\mbox{[}i\mbox{]} = i;

var packets = \mbox{[}\{ type\+: \textquotesingle{}message\textquotesingle{}, data\+: test\+Buffer.\+buffer \}, \{ type\+: \textquotesingle{}message\textquotesingle{}, data\+: \textquotesingle{}hello\textquotesingle{} \}\mbox{]};

parser.\+encode\+Payload(packets, function(encoded) \{ parser.\+decode\+Payload(encoded, function(packet, index, total) \{ var is\+Last = index + 1 == total; if (!is\+Last) \{ var buffer = new Int8\+Array(packet.\+data); // test\+Buffer \} else \{ var message = packet.\+data; // \textquotesingle{}hello\textquotesingle{} \} \}); \}); \`{}\`{}\`{}
\end{DoxyEnumerate}
\begin{DoxyEnumerate}
\item build your app bundle

\`{}\`{}\`{}bash \$ browserify app.\+js $>$ bundle.\+js \`{}\`{}\`{}
\end{DoxyEnumerate}
\begin{DoxyEnumerate}
\item include on your page

\`{}\`{}\`{}html $<$script src=\char`\"{}/path/to/bundle.\+js\char`\"{}$>$$<$/script$>$ \`{}\`{}\`{}
\end{DoxyEnumerate}\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8716}{}\doxysection{Features}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8716}

\begin{DoxyItemize}
\item Runs on browser and node.\+js seamlessly
\item Runs inside HTML5 Web\+Worker
\item Can encode and decode packets
\begin{DoxyItemize}
\item Encodes from/to Array\+Buffer or Blob when in browser, and Buffer or Array\+Buffer in Node
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8717}{}\doxysection{API}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8717}
Note\+: {\ttfamily cb(type)} means the type is a callback function that contains a parameter of type {\ttfamily type} when called.\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8718}{}\doxysubsection{Node}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8718}

\begin{DoxyItemize}
\item {\ttfamily encode\+Packet}
\begin{DoxyItemize}
\item Encodes a packet.
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily Object}\+: the packet to encode, has {\ttfamily type} and {\ttfamily data}.
\begin{DoxyItemize}
\item {\ttfamily data}\+: can be a {\ttfamily String}, {\ttfamily Number}, {\ttfamily Buffer}, {\ttfamily Array\+Buffer}
\end{DoxyItemize}
\item {\ttfamily Boolean}\+: optional, binary support
\item {\ttfamily Function}\+: callback, returns the encoded packet ({\ttfamily cb(\+String)})
\end{DoxyItemize}
\end{DoxyItemize}
\item {\ttfamily decode\+Packet}
\begin{DoxyItemize}
\item Decodes a packet. Data also available as an Array\+Buffer if requested.
\item Returns data as {\ttfamily String} or ({\ttfamily Blob} on browser, {\ttfamily Array\+Buffer} on Node)
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily String} $\vert$ {\ttfamily Array\+Buffer}\+: the packet to decode, has {\ttfamily type} and {\ttfamily data}
\item {\ttfamily String}\+: optional, the binary type
\end{DoxyItemize}
\end{DoxyItemize}
\item {\ttfamily encode\+Base64\+Packet}
\begin{DoxyItemize}
\item Encodes a packet with binary data in a base64 string ({\ttfamily String})
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily Object}\+: the packet to encode, has {\ttfamily type} and {\ttfamily data}
\item {\ttfamily Function}\+: callback, returns the base64 encoded message ({\ttfamily cb(\+String)})
\end{DoxyItemize}
\end{DoxyItemize}
\item {\ttfamily decode\+Base64\+Packet}
\begin{DoxyItemize}
\item Decodes a packet encoded in a base64 string.
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily String}\+: the base64 encoded message
\item {\ttfamily String}\+: optional, the binary type
\end{DoxyItemize}
\end{DoxyItemize}
\item {\ttfamily encode\+Payload}
\begin{DoxyItemize}
\item Encodes multiple messages (payload).
\item If any contents are binary, they will be encoded as base64 strings. Base64 encoded strings are marked with a b before the length specifier
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily Array}\+: an array of packets
\item {\ttfamily Boolean}\+: optional, binary support
\item {\ttfamily Function}\+: callback, returns the encoded payload ({\ttfamily cb(\+String)})
\end{DoxyItemize}
\end{DoxyItemize}
\item {\ttfamily decode\+Payload}
\begin{DoxyItemize}
\item Decodes data when a payload is maybe expected. Possible binary contents are decoded from their base64 representation.
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily String}\+: the payload
\item {\ttfamily String}\+: optional, the binary type
\item {\ttfamily Function}\+: callback, returns (cb({\ttfamily Object}\+: packet, {\ttfamily Number}\+:packet index, {\ttfamily Number}\+:packet total))
\end{DoxyItemize}
\end{DoxyItemize}
\item {\ttfamily encode\+Payload\+As\+Binary}
\begin{DoxyItemize}
\item Encodes multiple messages (payload) as binary.
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily Array}\+: an array of packets
\item {\ttfamily Function}\+: callback, returns the encoded payload ({\ttfamily cb(\+Buffer)})
\end{DoxyItemize}
\end{DoxyItemize}
\item {\ttfamily decode\+Payload\+As\+Binary}
\begin{DoxyItemize}
\item Decodes data when a payload is maybe expected. Strings are decoded by interpreting each byte as a key code for entries marked to start with 0. See description of encode\+Payload\+As\+Binary.
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily Buffer}\+: the buffer
\item {\ttfamily String}\+: optional, the binary type
\item {\ttfamily Function}\+: callback, returns the decoded packet ({\ttfamily cb(\+Object)})
\end{DoxyItemize}
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8719}{}\doxysubsection{Browser}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8719}

\begin{DoxyItemize}
\item {\ttfamily encode\+Payload\+As\+Array\+Buffer}
\begin{DoxyItemize}
\item Encodes multiple messages (payload) as binary.
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily Array}\+: an array of packets
\item {\ttfamily Function}\+: callback, returns the encoded payload ({\ttfamily cb(\+Array\+Buffer)})
\end{DoxyItemize}
\end{DoxyItemize}
\item {\ttfamily encode\+Payload\+As\+Blob}
\begin{DoxyItemize}
\item Encodes multiple messages (payload) as blob.
\item {\bfseries{Parameters}}
\begin{DoxyItemize}
\item {\ttfamily Array}\+: an array of packets
\item {\ttfamily Function}\+: callback, returns the encoded payload ({\ttfamily cb(\+Blob)})
\end{DoxyItemize}
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8720}{}\doxysection{Tests}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8720}
Standalone tests can be run with {\ttfamily make test} which will run both node.\+js and browser tests.

Browser tests are run using \href{https://github.com/defunctzombie/zuul}{\texttt{ zuul}}. (You must have zuul setup with a saucelabs account.)

You can run the tests locally using the following command\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{./node\_modules/.bin/zuul -\/-\/local 8080 -\/-\/ test/index.js }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8721}{}\doxysection{Support}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8721}
The support channels for {\ttfamily engine.\+io-\/parser} are the same as {\ttfamily socket.\+io}\+:
\begin{DoxyItemize}
\item \href{irc.freenode.net}{\texttt{ irc.\+freenode.\+net}} $\ast$$\ast$\#socket.\+io$\ast$$\ast$
\item \href{http://groups.google.com/group/socket_io}{\texttt{ Google Groups}}
\item \href{http://socket.io}{\texttt{ Website}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8722}{}\doxysection{Development}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8722}
To contribute patches, run tests or benchmarks, make sure to clone the repository\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{git clone git://github.com/LearnBoost/engine.io-\/parser.git }

\end{DoxyCode}


Then\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{cd engine.io-\/parser}
\DoxyCodeLine{npm install }

\end{DoxyCode}


See the {\ttfamily Tests} section above for how to run tests before submitting any patches.\hypertarget{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8723}{}\doxysection{License}\label{md_sfcode_node_modules_engine_io_parser_Readme_autotoc_md8723}
MIT 