|
11 | 11 | // Presence is a publish-subscribe mechanism and is used to broadcast
|
12 | 12 | // availability on the network (sometimes called "status" in chat, eg. online,
|
13 | 13 | // offline, or away).
|
14 |
| -// IQ (Info-Query) is a request response mechanism for data that requires a |
| 14 | +// IQ (Info/Query) is a request response mechanism for data that requires a |
15 | 15 | // response (eg. fetching an avatar or a list of client features).
|
16 | 16 | //
|
17 |
| -// Stanzas created using the structs in this package are not guaranteed to be |
18 |
| -// valid or enforce specific stanza semantics. |
| 17 | +// There are two APIs for creating stanzas in this package, a token based XML |
| 18 | +// stream API where the final stanza can be read from an xml.TokenReader, and a |
| 19 | +// struct based API that relies on embedding structs in this package into the |
| 20 | +// users own types. |
| 21 | +// Stanzas created using either API are not guaranteed to be valid or enforce |
| 22 | +// specific stanza semantics. |
19 | 23 | // For instance, using this package you could create an IQ without a unique ID,
|
20 | 24 | // which is illegal in XMPP.
|
21 | 25 | // Packages that require correct stanza semantics, such as the `mellium.im/xmpp`
|
|
26 | 30 | //
|
27 | 31 | // The stanza types in this package aren't very useful by themselves. To
|
28 | 32 | // transmit meaningful data our stanzas must contain a payload.
|
29 |
| -// To add a payload we use composition to create a new struct that contains the |
30 |
| -// payload as additional fields. |
| 33 | +// To add a payload with the struct based API we use composition to create a new |
| 34 | +// struct that contains the payload as additional fields. |
31 | 35 | // For example, XEP-0199: XMPP Ping defines an IQ stanza with a payload named
|
32 | 36 | // "ping" qualified by the "urn:xmpp:ping" namespace.
|
33 | 37 | // To implement this in our own code we might create a Ping struct similar to
|
|
40 | 44 | // Ping struct{} `xml:"urn:xmpp:ping ping"`
|
41 | 45 | // }
|
42 | 46 | //
|
| 47 | +// |
43 | 48 | // For details on marshaling and the use of the xml tag, refer to the
|
44 | 49 | // encoding/xml package.
|
| 50 | +// |
| 51 | +// We could also create a similar stanza with the token stream API: |
| 52 | +// |
| 53 | +// // PingIQ returns an xml.TokenReader that outputs a new IQ stanza with a |
| 54 | +// // ping payload. |
| 55 | +// func PingIQ(to jid.JID) xml.TokenReader { |
| 56 | +// start := xml.StartElement{Name: xml.Name{Space: "urn:xmpp:ping", Local: "ping"}} |
| 57 | +// return stanza.WrapIQ( |
| 58 | +// &stanza.IQ{To: to, Type: stanza.GetIQ}, |
| 59 | +// xmlstream.Wrap(nil, start) |
| 60 | +// ) |
| 61 | +// } |
45 | 62 | package stanza // import "mellium.im/xmpp/stanza"
|
0 commit comments