wire

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Wire

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

A Wire is allows communicating length-delimited bytes to and from the network or a buffer, up until some predefined maximum message length.

func NewWire

func NewWire(maxMsgLength uint32) *Wire

func (*Wire) IsNextMessageAllowed

func (w *Wire) IsNextMessageAllowed(r *bufio.Reader, l *rate.Limiter) (bool, error)

IsNextMessageAllowed will check if the next message is permitted by the rate limiter. It will wait for a new message to be available on the stream reader by peeking at the first 4 bytes representing the new message's length. If the rate limiter rejects the request, the rejected message is consumed from the reader and discarded. This way the sync with the sender is not broken.

func (*Wire) ReadOneFromWire

func (w *Wire) ReadOneFromWire(r io.Reader) (payload []byte, err error)

NOTE: This can block indefinitely if not enough bytes are forthcoming It can error if the stream unexpectedly closes, or the provided data is invalid

func (*Wire) WireEncode

func (w *Wire) WireEncode(b []byte) []byte

Jump to

Keyboard shortcuts

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