Documentation ¶
Overview ¶
Weechat protocol parser.
Weechats package allow decoding a message from weechat relay. Parser can be initialized as weechat.Protocol object that has a Decode() method which parses a full message. There is a private method to parse every objtype and parseObject takes in the objType and data returning the parsed object. Currently, parseObject can parse all the Core weechat object types.
There are a few more public methods, ParseString and ParseInt which provide public methods to parse the string and uint32 types.
Protocol Parsing ¶
Decode method returns a WeechatMessage object which includes various methods including a list of WeechatObjects and Msgid. They are the most used fields, but there is also the size and compression related information captured in the WeechatMessage object instances.
WeechatObjects are currently naive in implementation and uses a single Type with ObjType and Value parameters that captures the Core type of the obj and _any_ value type. You have to know the type of the Value or check it explicitly by looking at ObjType.
HDA is the most common data type. We use map[string]WeechatObject as the Value type, but in order to also capture other details like hpath, we created a wrapper around the value and Hda objects values are of WeechatHdaValue type. For now, it only has a Value and Hpath attributes, but in future we might add other fields if needed or even remove it. All the parsing related code lives in protocol.go
Message Handling ¶
Once a raw response has been parsed, weechat.HandleMessage is used to parse useful information from the Core types and return more useful objects by looking at WeechatMessage.Msgid.
Msgid for commands can be specified in the commands and the response will have those Msgids. Weechat also has some specific Msgids that it uses to signify the event type.
Currently, there are three commands that weeclient sends on start, apart from the authentication with custom Msgids. The rest are essentially the default Msgids.
(listbuffers) hdata buffer:gui_buffers() number,full_name,short_name,type,nicklist,title,local_variables, (listlines) hdata buffer:gui_buffers()/own_lines/last_line(-%(lines)d)/data date,displayed,prefix,message,buffer (nicklist) nicklist
Currently supported events ¶
weechat.HandleMessage currently only parses some Msgid types and then uses a catch-all handler for the rest of the types. It is up-to the callee to handle the rest of the types.
weechat.HandleMessage expects a handler of the type HandleWeechatMessage interface, which essentially is meant to be an interface that handles all the Core event types in Weechat: https://weechat.org/files/doc/stable/weechat_relay_protocol.en.html#message_identifier. Currently handled events include:
- listbuffers - This is a custom command which you can find above
- listlines - This is also a custom command.
- nicklist - This is a custom command too. Although, HandleNickList() is called on the msg object with no additional object types or parsing.
- _buffer_opened: When a new buffer is opened. Handler is same as "listbuffers" and HandleListBuffers() is called on the handler.
- _buffer_line_added: When a new line is added in any of the buffer. Handler is same as "listlines" and HandleLineAdded is called.
Index ¶
- Constants
- Variables
- func HandleMessage(msg *WeechatMessage, handler HandleWeechatMessage) error
- type ConnectionType
- type HandleWeechatMessage
- type Protocol
- type WeechatBuffer
- type WeechatConn
- type WeechatDict
- type WeechatHdaValue
- type WeechatLine
- type WeechatMessage
- type WeechatNick
- type WeechatNickDiff
- type WeechatObject
- type WeechatRelayConn
- type WeechatSendMessage
- type WeechatWebsocketConn
Constants ¶
const ( OBJ_INT = "int" OBJ_CHR = "chr" OBJ_LON = "lon" OBJ_STR = "str" OBJ_BUF = "buf" OBJ_PTR = "ptr" OBJ_TIM = "tim" OBJ_HTB = "htb" OBJ_HDA = "hda" OBJ_INF = "inf" OBJ_INL = "inl" OBJ_ARR = "arr" )
All the Core Weechat objecct types.
Variables ¶
var DebugPrint = false
Debug.
Functions ¶
func HandleMessage ¶
func HandleMessage(msg *WeechatMessage, handler HandleWeechatMessage) error
Parse the message into More useful data structures that can be used by higher level UI functions. It expects an interface which handles parsed structured output.
Types ¶
type ConnectionType ¶ added in v0.0.3
type ConnectionType int
const ( WebsocketConnection ConnectionType = iota RelayConnection )
type HandleWeechatMessage ¶
type HandleWeechatMessage interface { HandleListBuffers(map[string]*WeechatBuffer) HandleNickList(string, []*WeechatNick) HandleLineAdded(*WeechatLine) Default(*WeechatMessage) Debug(string) }
Interface for handler that handles various events.
type Protocol ¶
type Protocol struct { }
Protocol represents a parser for Weechat Relay Protocol and essentially parses messages from here: https://weechat.org/files/doc/stable/weechat_relay_protocol.en.html#messages
func (*Protocol) Decode ¶
func (p *Protocol) Decode(data []byte) (msg *WeechatMessage, err error)
This is the primary Pubic method to decode a single Weechat Message. It support zlib decompression of the compressed message.
func (*Protocol) ParseLen ¶
Parse the length of a string/message/anything. Just a proxy for parseInt.
func (*Protocol) ParseString ¶
Parse a single string. https://weechat.org/files/doc/stable/weechat_relay_protocol.en.html#object_string
type WeechatBuffer ¶
type WeechatBuffer struct { Lines []*WeechatLine ShortName string FullName string Number int32 Title string LocalVars map[WeechatObject]WeechatObject Path string }
func (*WeechatBuffer) GetLines ¶ added in v0.0.3
func (b *WeechatBuffer) GetLines(shouldColor bool) string
func (*WeechatBuffer) TitleStr ¶ added in v0.0.3
func (b *WeechatBuffer) TitleStr(shouldColor bool) string
Get the Title of the Buffer with color if asked for.
type WeechatConn ¶ added in v0.0.3
Weechat connection interface represents a connection to the weechat relay. There can be more than one way to connect to the weechat relay server and this interface wraps that complexity into a single interface.
func WeechatConnFactory ¶ added in v0.0.3
func WeechatConnFactory(connType ConnectionType, url string, path string, ssl bool) WeechatConn
type WeechatDict ¶
type WeechatDict map[string]WeechatObject
type WeechatHdaValue ¶
type WeechatHdaValue struct { Value []WeechatDict Hpath string }
func (WeechatHdaValue) DebugPrint ¶ added in v0.0.3
func (hda WeechatHdaValue) DebugPrint() string
type WeechatLine ¶
type WeechatLine struct { // Path of the buffer. Buffer string Date time.Time DatePrinted time.Time Displayed bool NotifyLevel int Highlight bool Tags []string Prefix string Message string }
All the information about a new line.
func (*WeechatLine) ToString ¶ added in v0.0.3
func (l *WeechatLine) ToString(shouldColor bool) string
Return the string representation of the line to be printed in the ui. Use optional coloring.
type WeechatMessage ¶
type WeechatMessage struct { // Size of the message when recieved including the length (4bytes). Size int // Size of the message after (optional) decompressing. SizeUncompressed int // Was zlib compressed used in the message body? Compressed bool // Uncompressed content of the message. If it wasn't compressed // this has the originl body of the message minus the length. Uncompressed []byte // optional message-id of the message. Msgid string // Object type. Type string // List of Weechat objects returned from the message. Object WeechatObject }
Represents a single message from weechat.
type WeechatNick ¶ added in v0.0.3
type WeechatNick struct { Group bool Visible bool Level int32 Name string Color string Prefix string PrefixColor string }
func (*WeechatNick) String ¶ added in v0.0.3
func (n *WeechatNick) String() string
type WeechatNickDiff ¶ added in v0.0.3
type WeechatNickDiff struct { WeechatNick Diff string }
type WeechatObject ¶
type WeechatObject struct { ObjType string Value interface{} }
Core weechat object. This represents a parsed Core object type. It doesn't currently capture all the data in a single object and kinda uses only a single untyped Value fields. In future, try to figure out something better here that alows optional fields for specific objects.
type WeechatRelayConn ¶ added in v0.0.3
type WeechatRelayConn struct { URL string // contains filtered or unexported fields }
func NewRelayConn ¶ added in v0.0.3
func NewRelayConn(url string) *WeechatRelayConn
func (*WeechatRelayConn) Connect ¶ added in v0.0.3
func (w *WeechatRelayConn) Connect() error
func (*WeechatRelayConn) Read ¶ added in v0.0.3
func (w *WeechatRelayConn) Read() ([]byte, error)
func (*WeechatRelayConn) Write ¶ added in v0.0.3
func (w *WeechatRelayConn) Write(data []byte) error
type WeechatSendMessage ¶
Object representing information needed to be sent.
func (*WeechatSendMessage) String ¶ added in v0.0.3
func (w *WeechatSendMessage) String() string
type WeechatWebsocketConn ¶ added in v0.0.3
func NewWebsocketConn ¶ added in v0.0.3
func NewWebsocketConn(host string, path string, ssl bool) *WeechatWebsocketConn
func (*WeechatWebsocketConn) Connect ¶ added in v0.0.3
func (w *WeechatWebsocketConn) Connect() error
func (*WeechatWebsocketConn) Read ¶ added in v0.0.3
func (w *WeechatWebsocketConn) Read() ([]byte, error)
func (*WeechatWebsocketConn) Write ¶ added in v0.0.3
func (w *WeechatWebsocketConn) Write(data []byte) error