<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style>On Jun 15, 2012, at 10:13 AM, Laurens Van Houtven wrote:</span><br style>
<br style><span style>&gt; Hi,</span><br style><span style>&gt;</span><br style><span style>&gt; I&#39;m trying to get browsers to communicate with an AMP API.</span><br style><br style><span style>This is also what &lt;</span><a href="https://launchpad.net/frack" target="_blank" style>https://launchpad.net/frack</a><span style>&gt; is doing.  I hope that it becomes a common enough practice that there&#39;s a library for it :).</span><br style>
<br style><span style>&gt; The issue is that while AMP is inherently a binary protocol, WebSockets transfer text (well, that&#39;s a lie: there&#39;s a binary version, but it&#39;s even less widely supported than WebSockets themselves -- and SockJS doesn&#39;t support it at all, although it&#39;s on the roadmap). So, I need an alternative, preferably 7-bit, serialization for AMP boxes.</span><br style>
<br style><span style>Did you immediately discard the obvious solution of &quot;base64 everything&quot;? :)</span></blockquote><div><br></div><div>I had success simply base64&#39;ing binary data.  And I believe encoding that is safe for binary data, but I may be wrong.</div>
<div><br></div><div>Use this:</div><div>            data = binascii.b2a_base64(bindata).strip() </div>