Add way to peek at Iq's payload element.

This commit is contained in:
Matt Goodall 2012-07-16 16:06:13 +01:00
parent 91b33a0f3d
commit e22b95e43e
1 changed files with 15 additions and 0 deletions

View File

@ -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"`