[tpm] delimiting/reading YAML documents across sockets

Stuart Watt stuart at morungos.com
Tue Jul 9 07:39:50 PDT 2013


Personally, I would suggest JSON, or even XML. YAML is fairly complex (it's advantage is human readability, not performance), and I'd suggest too complex, for network data. JSON, especially with JSON::XS, is fast, east, and handles newlines fine, apart from the packet-detection issue. 

I'd agree that separating packetizing from encoding is ideal, but if you don't want to do that, you could try a streaming parser, e.g., JSON::Streaming::Reader. For sending, you can then just dump the data out. For receiving, in theory this gives you an event-based API which might be a more natural fit. XML uses technique much more -- it's the basis for XMPP for example. I use streaming XML a lot for handling very large, even continuous, data, and it's not really too bad, although it does push some of the encoding/decoding back to you. 

Using indentation IMO makes the point of a streaming parser very dubious, which is another reason if you want to do streaming event-based reading to use either JSON, or even XML::Stream for reading and XML::Writer for sending. Personally, I doubt if there is ever going to be a safe application for streaming YAML. 

All the best
Stuart

On 2013-07-08, at 3:25 PM, Fulko Hew wrote:

> [PS. The same questions would apply to anyone who suggests
>  JSON as an alternative.]

--
Stuart Watt
stuart at morungos.com / twitter.com/morungos


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130709/186ae5e1/attachment.html>


More information about the toronto-pm mailing list