From 01011c81c6fafb7435a98c9bf2309082cf5b13f8 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 15 May 2023 21:19:30 +0200 Subject: Split XML token decoder logic into xmpp/decoder.go --- xmpp/decoder.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 xmpp/decoder.go (limited to 'xmpp/decoder.go') diff --git a/xmpp/decoder.go b/xmpp/decoder.go new file mode 100644 index 0000000..97329c7 --- /dev/null +++ b/xmpp/decoder.go @@ -0,0 +1,43 @@ +package xmpp + +import ( + "crypto/tls" + "encoding/xml" + "log" +) + +type decoder struct { + terminator chan bool + data chan xml.Token + decoder *xml.Decoder +} + +func newDecoder(conn *tls.Conn) decoder { + return decoder{ + make(chan bool), + make(chan xml.Token), + xml.NewDecoder(conn), + } +} + +func (r *decoder) run() { + for { + select { + case <-r.terminator: + return + default: + t, err := r.decoder.Token() + if err != nil { + log.Print(err) + } + if t != nil { + c := xml.CopyToken(t) + r.data <- c + } + } + } +} + +func (r *decoder) stop() { + r.terminator <- true +} -- cgit v1.2.3-70-g09d2