[Twisted-Python] AMP WebSockets bridging
glyph at twistedmatrix.com
Fri Jun 15 15:32:37 EDT 2012
On Jun 15, 2012, at 10:13 AM, Laurens Van Houtven wrote:
> I'm trying to get browsers to communicate with an AMP API.
This is also what <https://launchpad.net/frack> is doing. I hope that it becomes a common enough practice that there's a library for it :).
> 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.
Did you immediately discard the obvious solution of "base64 everything"? :)
> An issue I'm running into is an AMP ListOf. With the above code, ListOf still gets translated to a string, and obviously I want it to be a list. When that ListOf has actual data in it, I get the binary representation.
I would recommend implementing an entirely alternate serialization code path; specifically, one which adapts the existing AMP Argument objects to some new interface ('.toJSON()'), with a default adapter that uses the existing toString()/fromString(), and then specific adapters for those interfaces which need modification, like ListOf and Boolean.
More information about the Twisted-Python