From 3eb1c9f722fa23c3af8a5cc2b87706b5074bd423 Mon Sep 17 00:00:00 2001 From: Matt Goodall Date: Fri, 6 Jul 2012 16:24:32 +0100 Subject: [PATCH] Allow []byte, string or anything xml.Marshal'able to be sent. --- src/xmpp/stream.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index d5295f1..ab1024c 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -63,10 +63,28 @@ func (stream *Stream) UpgradeTLS(config *tls.Config) error { return nil } -func (stream *Stream) Send(s string) error { - if _, err := stream.conn.Write([]byte(s)); err != nil { +func (stream *Stream) Send(v interface{}) error { + + var bytes []byte + + switch v2 := v.(type) { + case []byte: + bytes = v2 + case string: + bytes = []byte(v2) + default: + b, err := xml.Marshal(v2) + if err != nil { + return err + } + bytes = b + } + + log.Println("send:", string(bytes)) + if _, err := stream.conn.Write(bytes); err != nil { return err } + return nil }