message

package
v0.0.0-...-5107381 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package message provides somewhat general-purpose helpers for handling network messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessBlocks

func ProcessBlocks(f *xivnet.Frame) []*xivnet.Block

ProcessBlocks returns a processed list of blocks from the provided frame.

Note this will not parse the blocks, as parsing could return errors. These errors should be handled on a per-block basis.

The processing will apply a higher resolution timestamp to each block and filter out excessive egress movement blocks. Because the FFXIV client spams the server with many temporally-close movement blocks during casts (presumably to ensure movement will interrupt casts), not many of these blocks are very useful for our purposes. Therefore, we filter them out during processing.

This processing must happen here since as soon as we handle blocks individually it's too late to dedup.

Types

type DecoderFactory

type DecoderFactory func(r io.Reader) FrameDecoder

DecoderFactory defines a constructor for a FrameDecoder

type FrameDecoder

type FrameDecoder interface {
	NextFrame() (*xivnet.Frame, error)
	DiscardDataUntilValid()
}

FrameDecoder defines any decoder that can read frames from the input reader

type MuxDecoder

type MuxDecoder struct {
	// contains filtered or unexported fields
}

MuxDecoder accepts byte data from any number of sources and stores data tagged with a source ID. It decodes full messages from each source and provides decoded messages via the NextFrame method. This is especially useful for handling multiple sources of data in a single goroutine. This same task could be done with goroutines, but it may lead to goroutine leaks when it is not clear or impossible to know when these sources of data appear or disappear. MuxDecoder is not thread-safe. It should either be used in a single-threaded context or be handled in a critical section.

func NewMuxDecoder

func NewMuxDecoder(decoderFactory DecoderFactory) *MuxDecoder

NewMuxDecoder creates a new multiplexer decoder

func (*MuxDecoder) NextFrame

func (m *MuxDecoder) NextFrame() (*xivnet.Frame, error)

NextFrame returns the next valid frame on the last updated decoder. This may be called multiple times per WriteData call. If there are no more full frames to be read, NextFrame() will return a nil frame with a nil error.

func (*MuxDecoder) WriteData

func (m *MuxDecoder) WriteData(sourceID uint32, message []byte)

WriteData sends the byte data to the correct decoder stream for handling. The next NextFrame call will return the result of calling NextFrame on the correct decoder. If the decoder stream doesn't exist, it creates a new one.

Jump to

Keyboard shortcuts

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