1
0
Fork 0

<iq/> stanza with generic payload and decode/encode.

This commit is contained in:
Matt Goodall 2012-07-08 10:13:02 +01:00
parent 3eb1c9f722
commit 300074fb07
1 changed files with 28 additions and 0 deletions

28
src/xmpp/stanza.go Normal file
View File

@ -0,0 +1,28 @@
package xmpp
import "encoding/xml"
// XMPP <iq/> stanza.
type Iq struct {
XMLName xml.Name `xml:"iq"`
Id string `xml:"id,attr"`
Type string `xml:"type,attr"`
Payload string `xml:",innerxml"`
}
// Encode the value to an XML string and set as the payload. See xml.Marshal
// for how the value is encoded.
func (iq *Iq) PayloadEncode(v interface{}) error {
bytes, err := xml.Marshal(v)
if err != nil {
return err
}
iq.Payload = string(bytes)
return nil
}
// Decode the payload (an XML string) into the given value. See xml.Unmarshal
// for how the value is decoded.
func (iq *Iq) PayloadDecode(v interface{}) error {
return xml.Unmarshal([]byte(iq.Payload), v)
}