ircmsg

package
v0.0.0-...-1a94ce6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ircmsg parses and serializes IRC protocol messages, including IRCv3 message tags.

Index

Constants

View Source
const IRCv3TagCap = 8191

IRCv3TagCap is the maximum allowed length of the encoded tag section.

Variables

View Source
var (
	// ErrLineTooLong indicates that a message exceeds the maximum allowed length.
	ErrLineTooLong = errors.New("ircmsg: line exceeds maximum length")
	// ErrInvalidMessage indicates that a message is malformed.
	ErrInvalidMessage = errors.New("ircmsg: malformed message")
	// ErrInvalidTag indicates that a message tag is malformed.
	ErrInvalidTag = errors.New("ircmsg: malformed tag")
	// ErrTooManyParams indicates that a message has more than 15 parameters.
	ErrTooManyParams = errors.New("ircmsg: too many parameters (>15)")
)

Functions

func EscapeTagValue

func EscapeTagValue(s string) string

EscapeTagValue escapes a tag value for the wire per the IRCv3 tag encoding.

func TruncateUTF8Safe

func TruncateUTF8Safe(s string, maxBytes int) string

TruncateUTF8Safe returns the longest prefix of s within maxBytes that ends on a rune boundary.

func UnescapeTagValue

func UnescapeTagValue(s string) string

UnescapeTagValue unescapes a wire-form tag value per the IRCv3 tag encoding.

Types

type Message

type Message struct {
	Source  string
	Command string
	Params  []string
	Tags    Tags
}

Message represents a single IRC protocol message.

func ParseLine

func ParseLine(b []byte) (Message, error)

ParseLine parses a single IRC message, collapsing runs of separator spaces.

func ParseLineStrict

func ParseLineStrict(b []byte) (Message, error)

ParseLineStrict parses a single IRC message, requiring each token separator to be a single space.

func (*Message) Bytes

func (m *Message) Bytes(maxLen int) ([]byte, error)

Bytes serializes the message to its wire form, returning an error if it is malformed or exceeds maxLen.

func (*Message) GetTag

func (m *Message) GetTag(key string) (string, bool)

GetTag returns the value of the tag with the given key and reports whether it is present.

func (*Message) HasTag

func (m *Message) HasTag(key string) bool

HasTag reports whether the message has a tag with the given key.

func (*Message) IsClientOnlyTag

func (m *Message) IsClientOnlyTag(key string) bool

IsClientOnlyTag reports whether the given tag key denotes a client-only tag.

func (*Message) NickUserHost

func (m *Message) NickUserHost() (NickUserHost, error)

NickUserHost parses the message source into its nick, user, and host components.

type NickUserHost

type NickUserHost struct {
	Nick string
	User string
	Host string
}

NickUserHost represents the nick, user, and host components of an IRC source.

func (*NickUserHost) String

func (n *NickUserHost) String() string

type Tags

type Tags map[string]string

Tags maps IRCv3 message tag keys to their values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL