io

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 3 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(dst, src []byte) (n int, err error)

Copy copies data from src to dst. If dst is not big enough, return an InsufficientBufferError.

Types

type Broadcaster

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

Broadcaster is a generic pull-based broadcaster. Broadcaster is unique in a sense that readers can come and go at anytime, and readers don't need to close or notify broadcaster.

func NewBroadcaster

func NewBroadcaster(source Reader, config *BroadcasterConfig) *Broadcaster

NewBroadcaster creates a new broadcaster. Source is expected to drop frames when any of the readers is slower than the source.

func (*Broadcaster) NewReader

func (broadcaster *Broadcaster) NewReader(copyFn func(interface{}) interface{}) Reader

NewReader creates a new reader. Each reader will retrieve the same data from the source. copyFn is used to copy the data from the source to individual readers. Broadcaster uses a small ring buffer, this means that slow readers might miss some data if they're really late and the data is no longer in the ring buffer.

func (*Broadcaster) ReplaceSource

func (broadcaster *Broadcaster) ReplaceSource(source Reader) error

ReplaceSource replaces the underlying source. This operation is thread safe.

func (*Broadcaster) Source

func (broadcaster *Broadcaster) Source() Reader

ReplaceSource retrieves the underlying source. This operation is thread safe.

type BroadcasterConfig

type BroadcasterConfig struct {
	// BufferSize configures the underlying ring buffer size that's being used
	// to avoid data lost for late readers. The default value is 32.
	BufferSize uint
	// PollDuration configures the sleep duration in waiting for new data to come.
	// The default value is 33 ms.
	PollDuration time.Duration
}

BroadcasterConfig is a config to control broadcaster behaviour

type InsufficientBufferError

type InsufficientBufferError struct {
	RequiredSize int
}

InsufficientBufferError tells the caller that the buffer provided is not sufficient/big enough to hold the whole data/sample.

func (*InsufficientBufferError) Error

func (e *InsufficientBufferError) Error() string

type Reader

type Reader interface {
	Read() (interface{}, error)
}

Reader is a generic data reader. In the future, interface{} should be replaced by a generic type to provide strong type.

type ReaderFunc

type ReaderFunc func() (interface{}, error)

ReaderFunc is a proxy type for Reader

func (ReaderFunc) Read

func (f ReaderFunc) Read() (interface{}, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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