diff options
author | xengineering <me@xengineering.eu> | 2023-05-15 21:19:30 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-05-15 21:19:30 +0200 |
commit | 01011c81c6fafb7435a98c9bf2309082cf5b13f8 (patch) | |
tree | eeb6f7c79147ce689dc9d803b4202f9c13561523 /xmpp/decoder.go | |
parent | 8023777ac1b0171783e1c55f67a6179d63708272 (diff) | |
download | limox-01011c81c6fafb7435a98c9bf2309082cf5b13f8.tar limox-01011c81c6fafb7435a98c9bf2309082cf5b13f8.tar.zst limox-01011c81c6fafb7435a98c9bf2309082cf5b13f8.zip |
Split XML token decoder logic into xmpp/decoder.go
Diffstat (limited to 'xmpp/decoder.go')
-rw-r--r-- | xmpp/decoder.go | 43 |
1 files changed, 43 insertions, 0 deletions
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 +} |