diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go new file mode 100644 index 0000000..dc08d22 --- /dev/null +++ b/src/xmpp/stanza.go @@ -0,0 +1,28 @@ +package xmpp + +import "encoding/xml" + +// XMPP 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) +}