1
0
Fork 0

Combine Stream's Decode and DecodeElement methods.

This commit is contained in:
Matt Goodall 2012-07-12 00:56:35 +01:00
parent f97ed9ea37
commit e95528641b
3 changed files with 10 additions and 14 deletions

View File

@ -34,7 +34,7 @@ func NewClientXMPP(stream *Stream, jid JID, password string, config *ClientConfi
// Read features. // Read features.
f := new(features) f := new(features)
if err := stream.Decode(f); err != nil { if err := stream.Decode(f, nil); err != nil {
return nil, err return nil, err
} }
@ -103,7 +103,7 @@ func startTLS(stream *Stream, config *ClientConfig) error {
} }
p := tlsProceed{} p := tlsProceed{}
if err := stream.Decode(&p); err != nil { if err := stream.Decode(&p, nil); err != nil {
return err return err
} }
@ -161,7 +161,7 @@ func authenticateResponse(stream *Stream) error {
return nil return nil
case "failure": case "failure":
f := new(saslFailure) f := new(saslFailure)
if err := stream.DecodeElement(f, se); err != nil { if err := stream.Decode(f, se); err != nil {
return err return err
} }
return fmt.Errorf("Authentication failed: %s", f.Reason.Local) return fmt.Errorf("Authentication failed: %s", f.Reason.Local)
@ -191,7 +191,7 @@ func bindResource(stream *Stream, jid JID) (JID, error) {
} }
resp := Iq{} resp := Iq{}
err := stream.Decode(&resp) err := stream.Decode(&resp, nil)
if err != nil { if err != nil {
return JID{}, err return JID{}, err
} }

View File

@ -175,15 +175,11 @@ func (stream *Stream) Skip() error {
return stream.dec.Skip() return stream.dec.Skip()
} }
// Decode the next stanza. Works like xml.Unmarshal but reads from the stream's // Decode a stanza.
// connection. // If start is not nil, the stanza for the start element that's already been
func (stream *Stream) Decode(v interface{}) error { // consumed is read. A nil start will read the next stanza in the stream.
return stream.DecodeElement(v, nil) // See xml.Decoder.DecodeElement for decoding rules.
} func (stream *Stream) Decode(v interface{}, start *xml.StartElement) error {
// Decode the stanza with the given start element. Works like
// xml.Decoder.DecodeElement.
func (stream *Stream) DecodeElement(v interface{}, start *xml.StartElement) error {
// Explicity lookup next start element to ensure stream is validated, // Explicity lookup next start element to ensure stream is validated,
// stanza is logged, etc. // stanza is logged, etc.

View File

@ -171,7 +171,7 @@ func (x *XMPP) receiver() {
log.Fatal("Unexected element: %T %v", start, start) log.Fatal("Unexected element: %T %v", start, start)
} }
err = x.stream.DecodeElement(v, start) err = x.stream.Decode(v, start)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }