buffer

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsString added in v0.4.0

func ContainsString(a []string, x string) bool

ContainsString tells whether a contains x.

func MissingStrings added in v0.4.0

func MissingStrings(a []string, b []string) []string

MissingStrings returns the disjunction between given slices: a - b.

Types

type Buffer added in v0.4.0

type Buffer struct {
	Elements []Element     `json:"elements"`
	Len      int           `json:"len"` // Length of the Buffer. When the buffer is full, oldest element will be removed.
	Mux      *sync.RWMutex `json:"mux"`
}

Buffer is the buffer with messages.

func NewBuffer added in v0.4.0

func NewBuffer(size int) *Buffer

NewBuffer creates new buffer.

func (*Buffer) Add added in v0.4.0

func (buf *Buffer) Add(el Element) error

Add adds the given element in buffer. When the buffer is full, oldest element will be removed.

func (*Buffer) Digest added in v0.4.0

func (buf *Buffer) Digest() []string

Digest returns a slice with elements ids.

func (*Buffer) ElementsFromIDs added in v0.4.0

func (buf *Buffer) ElementsFromIDs(digest []string) []Element

ElementsFromIDs returns a slice with elements from given IDs list.

func (*Buffer) IncrementGossipCount added in v0.4.0

func (buf *Buffer) IncrementGossipCount()

IncrementGossipCount increments gossip count for each elements from buffer.

func (*Buffer) Length added in v0.4.0

func (buf *Buffer) Length() int

Length returns number of elements in buffer.

func (*Buffer) Messages added in v0.4.0

func (buf *Buffer) Messages(withInternals bool) []any

Messages returns a slice with messages for each element in buffer. If withInternals parameter is false, Messages returns only user (not internal) messages.

type Element added in v0.4.0

type Element struct {
	ID           string    `json:"id"`
	Timestamp    time.Time `json:"timestamp"`
	Msg          any       `json:"msg"`
	CallbackType string    `json:"callbackType"`
	GossipCount  int64     `json:"gossipCount"` // number of rounds since the element is in buffer
	Internal     bool      `json:"internal"`    // true if the element is an internal element, not a user element
}

Element is an element from messages buffer.

func NewElement added in v0.4.0

func NewElement(msg any, cbType string, internal bool) (Element, error)

NewElement creates new buffer element with given message and callback type.

Jump to

Keyboard shortcuts

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