<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>> Hi,</span><br style><span style>></span><br style><span style>> I'm trying to get browsers to communicate with an AMP API.</span><br style><br style><span style>This is also what <</span><a href="https://launchpad.net/frack" target="_blank" style>https://launchpad.net/frack</a><span style>> is doing. I hope that it becomes a common enough practice that there's a library for it :).</span><br style>
<br style><span style>> The issue is that while AMP is inherently a binary protocol, WebSockets transfer text (well, that's a lie: there's a binary version, but it's even less widely supported than WebSockets themselves -- and SockJS doesn't support it at all, although it'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 "base64 everything"? :)</span></blockquote><div><br></div><div>I had success simply base64'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>