Message format in JSON instead of XML
Martin Atkins
mart at degeneration.co.uk
Wed Nov 7 19:53:09 UTC 2007
Slavey Karadzhov wrote:
> Hi all,
> I am interested in modifying Djabberd to send messages in JSON format
> instead of XML. Is this possible and can you point me where to look in
> the code?
>
In theory there's no reason why you can't do this, though it probably
won't be easy because several parts of DJabberd works directly on
objects representing XML elements.
If you can define a complete mapping of all possible XML-based XMPP
stanzas to JSON and a matching reverse mapping, then you could implement
this by subclassing DJabberd::Connection and overriding the write_stanza
method to transform the data into JSON before writing to the stream.
You'd also need to override and wrap event_read to read in JSON instead
of XML and then turn it into a convincing enough DOM tree that the rest
of DJabberd would be able to process it.
I think by the time you'd done all this you'd probably have just traded
the overhead of sending XML over the wire for the processing overhead of
constantly marshalling between JSON and XML, and if your JSON structure
was indeed able to represent any possible XML DOM it probably wouldn't
be much smaller than the equivalent XML after all.
If you have a specific application in mind there's probably an easier
way of doing it using a plugin, but I can't speculate on that without
more information.
More information about the Djabberd
mailing list