From 89d44601930f4a9452fd40c2262652b1a847a8cf Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 4 Jun 2023 17:12:04 +0200 Subject: Re-implement XML encoding --- xmpp/encoder_decoder.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'xmpp/encoder_decoder.go') diff --git a/xmpp/encoder_decoder.go b/xmpp/encoder_decoder.go index c2d0423..14113a6 100644 --- a/xmpp/encoder_decoder.go +++ b/xmpp/encoder_decoder.go @@ -1,11 +1,44 @@ package xmpp +import ( + "encoding/xml" + "log" + "os" +) + type encoderDecoder struct{ session *session + ct *xml.Encoder // client transport encoder + cl *xml.Encoder // client log encoder } func newEncoderDecoder(s *session) encoderDecoder { - ed := encoderDecoder{s} + ed := encoderDecoder{} + + ed.session = s + + ed.ct = xml.NewEncoder(s.transport) + ed.ct.Indent("", " ") + + ed.cl = xml.NewEncoder(os.Stdout) + ed.cl.Indent("C: ", " ") return ed } + +func (ed *encoderDecoder) encodeToken(t xml.Token) error { + var err error + defer func() { if err != nil { log.Println(err) } }() + + err = ed.ct.EncodeToken(t) + if err != nil { return err } + err = ed.ct.Flush() + if err != nil { return err } + + err = ed.cl.EncodeToken(t) + if err != nil { return err } + err = ed.cl.Flush() + if err != nil { return err } + + return nil +} -- cgit v1.2.3-70-g09d2