\href{http://travis-ci.org/socketio/socket.io-parser}{\texttt{ }} \href{http://badge.fury.io/js/socket.io-parser}{\texttt{ }}

A socket.\+io encoder and decoder written in Java\+Script complying with version {\ttfamily 4} of \href{https://github.com/socketio/socket.io-protocol}{\texttt{ socket.\+io-\/protocol}}. Used by \href{https://github.com/automattic/socket.io}{\texttt{ socket.\+io}} and \href{https://github.com/automattic/socket.io-client}{\texttt{ socket.\+io-\/client}}.\hypertarget{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27926}{}\doxysection{Parser API}\label{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27926}
socket.\+io-\/parser is the reference implementation of socket.\+io-\/protocol. Read the full API here\+: \href{https://github.com/learnboost/socket.io-protocol}{\texttt{ socket.\+io-\/protocol}}.\hypertarget{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27927}{}\doxysection{Example Usage}\label{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27927}
\hypertarget{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27928}{}\doxysubsection{Encoding and decoding a packet}\label{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27928}

\begin{DoxyCode}{0}
\DoxyCodeLine{var parser = require('socket.io-\/parser');}
\DoxyCodeLine{var encoder = new parser.Encoder();}
\DoxyCodeLine{var packet = \{}
\DoxyCodeLine{  type: parser.EVENT,}
\DoxyCodeLine{  data: 'test-\/packet',}
\DoxyCodeLine{  id: 13}
\DoxyCodeLine{\};}
\DoxyCodeLine{encoder.encode(packet, function(encodedPackets) \{}
\DoxyCodeLine{  var decoder = new parser.Decoder();}
\DoxyCodeLine{  decoder.on('decoded', function(decodedPacket) \{}
\DoxyCodeLine{    // decodedPacket.type == parser.EVENT}
\DoxyCodeLine{    // decodedPacket.data == 'test-\/packet'}
\DoxyCodeLine{    // decodedPacket.id == 13}
\DoxyCodeLine{  \});}
\DoxyCodeLine{}
\DoxyCodeLine{  for (var i = 0; i < encodedPackets.length; i++) \{}
\DoxyCodeLine{    decoder.add(encodedPackets[i]);}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27929}{}\doxysubsection{Encoding and decoding a packet with binary data}\label{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27929}

\begin{DoxyCode}{0}
\DoxyCodeLine{var parser = require('socket.io-\/parser');}
\DoxyCodeLine{var encoder = new parser.Encoder();}
\DoxyCodeLine{var packet = \{}
\DoxyCodeLine{  type: parser.BINARY\_EVENT,}
\DoxyCodeLine{  data: \{i: new Buffer(1234), j: new Blob([new ArrayBuffer(2)])\}}
\DoxyCodeLine{  id: 15}
\DoxyCodeLine{\};}
\DoxyCodeLine{encoder.encode(packet, function(encodedPackets) \{}
\DoxyCodeLine{  var decoder = new parser.Decoder();}
\DoxyCodeLine{  decoder.on('decoded', function(decodedPacket) \{}
\DoxyCodeLine{    // decodedPacket.type == parser.BINARY\_EVENT}
\DoxyCodeLine{    // Buffer.isBuffer(decodedPacket.data.i) == true}
\DoxyCodeLine{    // Buffer.isBuffer(decodedPacket.data.j) == true}
\DoxyCodeLine{    // decodedPacket.id == 15}
\DoxyCodeLine{  \});}
\DoxyCodeLine{}
\DoxyCodeLine{  for (var i = 0; i < encodedPackets.length; i++) \{}
\DoxyCodeLine{    decoder.add(encodedPackets[i]);}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}
 See the test suite for more examples of how socket.\+io-\/parser is used.\hypertarget{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27930}{}\doxysection{License}\label{md_sfcode_node_modules_socket_io_parser_Readme_autotoc_md27930}
MIT 