summaryrefslogtreecommitdiffstats
path: root/irc/message.go
diff options
context:
space:
mode:
authorRobert Gerus <arachnist@i.am-a.cat>2015-12-23 20:26:57 +0100
committerRobert Gerus <arachnist@i.am-a.cat>2015-12-23 20:26:57 +0100
commita7eefc7daf05bae8e83ef96f65b288215459f7a6 (patch)
treecf79b5a4eb1b21f01f29aac6ac3f930b885d89d0 /irc/message.go
parent09286f3defa2f9368b645a4905a19cb0f521dafd (diff)
downloadgorepost-a7eefc7daf05bae8e83ef96f65b288215459f7a6.tar.gz
gorepost-a7eefc7daf05bae8e83ef96f65b288215459f7a6.tar.bz2
gorepost-a7eefc7daf05bae8e83ef96f65b288215459f7a6.tar.xz
gorepost-a7eefc7daf05bae8e83ef96f65b288215459f7a6.zip
Give explicit notice on message truncation.
Fixes #1
Diffstat (limited to 'irc/message.go')
-rw-r--r--irc/message.go32
1 files changed, 28 insertions, 4 deletions
diff --git a/irc/message.go b/irc/message.go
index 2f8971a..e1d448b 100644
--- a/irc/message.go
+++ b/irc/message.go
@@ -288,12 +288,36 @@ func (m *Message) Bytes() []byte {
buffer.WriteString(m.Trailing)
}
- // We need the limit the buffer length.
- if buffer.Len() > (maxLength) {
- buffer.Truncate(maxLength)
+ return buffer.Bytes()
+}
+
+func (m *Message) WireLen() int {
+
+ buffer := new(bytes.Buffer)
+
+ // Message prefix
+ if m.Prefix != nil {
+ buffer.WriteByte(prefix)
+ m.Prefix.writeTo(buffer)
+ buffer.WriteByte(space)
}
- return buffer.Bytes()
+ // Command is required
+ buffer.WriteString(m.Command)
+
+ // Space separated list of arguments
+ if len(m.Params) > 0 {
+ buffer.WriteByte(space)
+ buffer.WriteString(strings.Join(m.Params, string(space)))
+ }
+
+ if len(m.Trailing) > 0 || m.EmptyTrailing {
+ buffer.WriteByte(space)
+ buffer.WriteByte(prefix)
+ buffer.WriteString(m.Trailing)
+ }
+
+ return buffer.Len()
}
// String returns a string representation of this message.