~samwhited/xmpp

e885bb6a8a8ed8556380b827912a1c175fc742c4 — Sam Whited 1 year, 9 months ago eb14c1f
all: move encoding funcs into internal/marshal
3 files changed, 10 insertions(+), 10 deletions(-)

R internal/{encode.go => marshal/encode.go}
M mux/mux_test.go
M session.go
R internal/encode.go => internal/marshal/encode.go +2 -3
@@ 2,7 2,7 @@
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

package internal
package marshal

import (
	"bytes"


@@ 11,8 11,7 @@ import (
	"mellium.im/xmlstream"
)

// TODO: functions in this file are very inefficient, but doing it in a saner
// way requires significant changes to encoding/xml.
// BUG(ssw): Functions in this package are extremely inefficient.

// EncodeXML writes the XML encoding of v to the stream.
//

M mux/mux_test.go => mux/mux_test.go +3 -3
@@ 15,7 15,7 @@ import (

	"mellium.im/xmlstream"
	"mellium.im/xmpp"
	"mellium.im/xmpp/internal"
	"mellium.im/xmpp/internal/marshal"
	"mellium.im/xmpp/internal/ns"
	"mellium.im/xmpp/internal/xmpptest"
	"mellium.im/xmpp/mux"


@@ 94,10 94,10 @@ type testEncoder struct {
}

func (e testEncoder) Encode(v interface{}) error {
	return internal.EncodeXML(e.TokenWriter, v)
	return marshal.EncodeXML(e.TokenWriter, v)
}
func (e testEncoder) EncodeElement(v interface{}, start xml.StartElement) error {
	return internal.EncodeXMLElement(e.TokenWriter, v, start)
	return marshal.EncodeXMLElement(e.TokenWriter, v, start)
}

func TestFallback(t *testing.T) {

M session.go => session.go +5 -4
@@ 18,6 18,7 @@ import (
	"mellium.im/xmlstream"
	"mellium.im/xmpp/dial"
	"mellium.im/xmpp/internal"
	"mellium.im/xmpp/internal/marshal"
	"mellium.im/xmpp/internal/ns"
	"mellium.im/xmpp/jid"
	"mellium.im/xmpp/stanza"


@@ 481,11 482,11 @@ func (rw *responseChecker) EncodeToken(t xml.Token) error {
}

func (rw *responseChecker) Encode(v interface{}) error {
	return internal.EncodeXML(rw, v)
	return marshal.EncodeXML(rw, v)
}

func (rw *responseChecker) EncodeElement(v interface{}, start xml.StartElement) error {
	return internal.EncodeXMLElement(rw, v, start)
	return marshal.EncodeXMLElement(rw, v, start)
}

// Feature checks if a feature with the given namespace was advertised


@@ 667,7 668,7 @@ func (s *Session) Encode(v interface{}) error {
	s.out.Lock()
	defer s.out.Unlock()

	return internal.EncodeXML(s.out.e, v)
	return marshal.EncodeXML(s.out.e, v)
}

// EncodeElement writes the XML encoding of v to the stream, using start as the


@@ 678,7 679,7 @@ func (s *Session) EncodeElement(v interface{}, start xml.StartElement) error {
	s.out.Lock()
	defer s.out.Unlock()

	return internal.EncodeXMLElement(s.out.e, v, start)
	return marshal.EncodeXMLElement(s.out.e, v, start)
}

// Send transmits the first element read from the provided token reader.