@@ 5,7 5,6 @@
package xmpp
import (
- "bytes"
"context"
"crypto/tls"
"encoding/xml"
@@ 660,20 659,7 @@ func (s *Session) Encode(v interface{}) error {
s.out.Lock()
defer s.out.Unlock()
- // TODO: this is very inefficient, but doing it in a saner way requires
- // significant changes in encoding/xml.
- // We can't just encode directly to the connection because the token stream
- // is being manipulated (eg. to add missing id's on IQ stanzas).
- var b bytes.Buffer
- err := xml.NewEncoder(&b).Encode(v)
- if err != nil {
- return err
- }
- _, err = xmlstream.Copy(s.out.e, xml.NewDecoder(&b))
- if err != nil {
- return err
- }
- return s.out.e.Flush()
+ return internal.EncodeXML(s.out.e, v)
}
// EncodeElement writes the XML encoding of v to the stream, using start as the
@@ 684,20 670,7 @@ func (s *Session) EncodeElement(v interface{}, start xml.StartElement) error {
s.out.Lock()
defer s.out.Unlock()
- // TODO: this is very inefficient, but doing it in a saner way requires
- // significant changes in encoding/xml.
- // We can't just encode directly to the connection because the token stream
- // is being manipulated (eg. to add missing id's on IQ stanzas).
- var b bytes.Buffer
- err := xml.NewEncoder(&b).EncodeElement(v, start)
- if err != nil {
- return err
- }
- _, err = xmlstream.Copy(s.out.e, xml.NewDecoder(&b))
- if err != nil {
- return err
- }
- return s.out.e.Flush()
+ return internal.EncodeXMLElement(s.out.e, v, start)
}
// Send transmits the first element read from the provided token reader.