aboutsummaryrefslogtreecommitdiff
path: root/conn.go
diff options
context:
space:
mode:
Diffstat (limited to 'conn.go')
-rw-r--r--conn.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/conn.go b/conn.go
new file mode 100644
index 0000000..ac3787c
--- /dev/null
+++ b/conn.go
@@ -0,0 +1,42 @@
+package irc
+
+import (
+ "bufio"
+ "net"
+ "slices"
+)
+
+type Conn struct {
+ netConn net.Conn
+ bufReader *bufio.Reader
+}
+
+func NewConn(netConn net.Conn) Conn {
+ return Conn{
+ netConn: netConn,
+ bufReader: bufio.NewReader(netConn),
+ }
+}
+
+func (c *Conn) ReadMessage() (msg Message, err error) {
+ raw, err := c.bufReader.ReadSlice('\n')
+ if err != nil {
+ return
+ }
+
+ if raw[len(raw) - 1] == '\r' {
+ raw = raw[:len(raw) - 1]
+ }
+
+ msg, err = Parse(slices.Clone(raw))
+
+ return
+}
+
+func (c *Conn) Write(p []byte) (n int, err error) {
+ return c.netConn.Write(p)
+}
+
+func (c *Conn) WriteString(s string) (n int, err error) {
+ return c.netConn.Write(stringToBytes(s))
+}