~samwhited/xmpp

69e49f40e6934d45ed9d5f9f5f9078c88be57a59 — Sam Whited 1 year, 7 months ago 8265074
xmpp: use new internal encode functions
1 files changed, 2 insertions(+), 29 deletions(-)

M session.go
M session.go => session.go +2 -29
@@ 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.