From e95528641b2a17f14dd71cf1341405e554b3d8ea Mon Sep 17 00:00:00 2001 From: Matt Goodall Date: Thu, 12 Jul 2012 00:56:35 +0100 Subject: [PATCH] Combine Stream's Decode and DecodeElement methods. --- src/xmpp/client.go | 8 ++++---- src/xmpp/stream.go | 14 +++++--------- src/xmpp/xmpp.go | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/xmpp/client.go b/src/xmpp/client.go index 9a30638..f2562aa 100644 --- a/src/xmpp/client.go +++ b/src/xmpp/client.go @@ -34,7 +34,7 @@ func NewClientXMPP(stream *Stream, jid JID, password string, config *ClientConfi // Read features. f := new(features) - if err := stream.Decode(f); err != nil { + if err := stream.Decode(f, nil); err != nil { return nil, err } @@ -103,7 +103,7 @@ func startTLS(stream *Stream, config *ClientConfig) error { } p := tlsProceed{} - if err := stream.Decode(&p); err != nil { + if err := stream.Decode(&p, nil); err != nil { return err } @@ -161,7 +161,7 @@ func authenticateResponse(stream *Stream) error { return nil case "failure": f := new(saslFailure) - if err := stream.DecodeElement(f, se); err != nil { + if err := stream.Decode(f, se); err != nil { return err } return fmt.Errorf("Authentication failed: %s", f.Reason.Local) @@ -191,7 +191,7 @@ func bindResource(stream *Stream, jid JID) (JID, error) { } resp := Iq{} - err := stream.Decode(&resp) + err := stream.Decode(&resp, nil) if err != nil { return JID{}, err } diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index 7f5b850..2c20335 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -175,15 +175,11 @@ func (stream *Stream) Skip() error { return stream.dec.Skip() } -// Decode the next stanza. Works like xml.Unmarshal but reads from the stream's -// connection. -func (stream *Stream) Decode(v interface{}) error { - return stream.DecodeElement(v, nil) -} - -// Decode the stanza with the given start element. Works like -// xml.Decoder.DecodeElement. -func (stream *Stream) DecodeElement(v interface{}, start *xml.StartElement) error { +// Decode a stanza. +// If start is not nil, the stanza for the start element that's already been +// consumed is read. A nil start will read the next stanza in the stream. +// See xml.Decoder.DecodeElement for decoding rules. +func (stream *Stream) Decode(v interface{}, start *xml.StartElement) error { // Explicity lookup next start element to ensure stream is validated, // stanza is logged, etc. diff --git a/src/xmpp/xmpp.go b/src/xmpp/xmpp.go index 057efdd..c248d3e 100644 --- a/src/xmpp/xmpp.go +++ b/src/xmpp/xmpp.go @@ -171,7 +171,7 @@ func (x *XMPP) receiver() { log.Fatal("Unexected element: %T %v", start, start) } - err = x.stream.DecodeElement(v, start) + err = x.stream.Decode(v, start) if err != nil { log.Fatal(err) }