Open mremond opened 5 years ago
@genofire Any opinion on this? Do you like the prototype API to create packets better ?
unnecessary complicated for me the source code is easier to read, if it is formated like before.
Thanks for feedback. I committed my exploration in that branch: https://github.com/FluuxIO/go-xmpp/tree/builder-exploration/pkg/stanza to give you a better idea.
I feel that at some point the code may be difficult to navigate, with the pure parsing / packet formatting part, being mixed with client, component workflow and connection manager.
Separating the stanza building, marshalling and unmarshalling maybe help structure the code better as it grows (and I did not add test modules for all the structure generation, yet).
I think it should still be possible to use the full expending stanza version as well.
Anyway, still thinking about it, as you find this complicated. Maybe I will end up doing something in between (move to a separate package but remove the builder interface).
I am also afraid that godoc will become unusable if we do no split the XML marshalling / unmarshalling part: https://godoc.org/gosrc.io/xmpp
Using pointers, I managed to have a prototype of approach that can further reduce building an IQ with payload, as follows:
iq := stanza.NewIQ(stanza.Attrs{Type: "get", To: "service.localhost", Id: "disco-get-1"})
disco := iq.DiscoInfo()
disco.AddIdentity("Test Component", "gateway", "service")
disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1")
@genofire Several things to note for upgrade:
Other than that, you are not force to use shortcuts and can keep on relying on building the stanza with structs, as before.
Currently, building a stanza can lead to quite lengthy code, like the following:
I am exploring ways to make the code more compact and more guided through helpers (usable with code completin) with a code like this:
What do you think?