forked from chteufleur/go-xmpp
Add way to peek at Iq's payload element.
This commit is contained in:
parent
91b33a0f3d
commit
e22b95e43e
|
|
@ -1,6 +1,7 @@
|
||||||
package xmpp
|
package xmpp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
@ -33,6 +34,20 @@ func (iq *Iq) PayloadDecode(v interface{}) error {
|
||||||
return xml.Unmarshal([]byte(iq.Payload), v)
|
return xml.Unmarshal([]byte(iq.Payload), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the name of the payload element.
|
||||||
|
func (iq *Iq) PayloadName() (name xml.Name) {
|
||||||
|
dec := xml.NewDecoder(bytes.NewBufferString(iq.Payload))
|
||||||
|
tok, err := dec.Token()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
start, ok := tok.(xml.StartElement)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return start.Name
|
||||||
|
}
|
||||||
|
|
||||||
// XMPP <message/> stanza.
|
// XMPP <message/> stanza.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
XMLName xml.Name `xml:"message"`
|
XMLName xml.Name `xml:"message"`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue