stdtypes

package
v0.0.0-...-9727c61 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const Separator = "/"

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {

	// Src returns the module that emitted the event.
	// While this information is not always necessary for the system operation,
	// it is useful for analyzing event traces and debugging.
	Src() ModuleID

	// NewSrc returns a new Event that has the given source module
	// and is otherwise identical to the original event.
	NewSrc(newSrc ModuleID) Event

	// Dest returns the destination module of the event.
	Dest() ModuleID

	// NewDest returns a new Event that has the given destination module
	// and is otherwise identical to the original event.
	NewDest(newDest ModuleID) Event

	// ToBytes returns a serialized representation of the event
	// as a slice of bytes from which the event can be reconstructed.
	// Note that ToBytes does not necessarily guarantee the output to be deterministic.
	// Even multiple subsequent calls to ToBytes on the same event object might return different byte slices.
	// If an error occurs during serialization, ToBytes returns a nil byte slice and a non-nil error.
	ToBytes() ([]byte, error)

	// ToString returns a human-readable representation of the event.
	// While not used by the runtime itself, it can be used by associated tools.
	// Conventionally, this representation is JSON.
	ToString() string
}

type EventList

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

EventList represents a list of Events, e.g. as produced by a module.

func EmptyList

func EmptyList() *EventList

EmptyList returns an empty EventList. TODO: consider passing EventList by value here and everywhere else.

func ListOf

func ListOf(events ...Event) *EventList

ListOf returns EventList containing the given elements.

func (*EventList) Filter

func (el *EventList) Filter(predicate func(event Event) bool) *EventList

Filter returns a new event list containing only those items for which predicate returns true.

func (*EventList) Head

func (el *EventList) Head(n int) *EventList

Head returns the first up to n events in the list as a new list. The original list is not modified.

func (*EventList) Iterator

func (el *EventList) Iterator() *EventListIterator

Iterator returns a pointer to an EventListIterator object used to iterate over the events in this list, starting from the beginning of the list.

func (*EventList) Len

func (el *EventList) Len() int

Len returns the number of events in the EventList.

func (*EventList) PushBack

func (el *EventList) PushBack(event Event) *EventList

PushBack appends an event to the end of the list. Returns the EventList itself, for the convenience of chaining multiple calls to PushBack.

func (*EventList) PushBackList

func (el *EventList) PushBackList(newEvents *EventList) *EventList

PushBackList appends all events in newEvents to the end of the current EventList.

func (*EventList) PushBackSlice

func (el *EventList) PushBackSlice(events []Event) *EventList

PushBackSlice appends all events in newEvents to the end of the current EventList.

func (*EventList) RemoveFront

func (el *EventList) RemoveFront(n int) int

RemoveFront removes the first up to n events from the list. Returns the number of events actually removed.

func (*EventList) Slice

func (el *EventList) Slice() []Event

Slice returns a slice representation of the current state of the list. The returned slice only contains pointers to the events in this list, no deep copying is performed. Any modifications performed on the events will affect the contents of both the EventList and the returned slice.

type EventListIterator

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

EventListIterator is an object returned from EventList.Iterator used to iterate over the elements (Events) of an EventList using the iterator's Next method.

func (*EventListIterator) Next

func (eli *EventListIterator) Next() Event

Next will return the next Event until the end of the associated EventList is encountered. Thereafter, it will return nil.

type Message

type Message interface {
	ToBytes() ([]byte, error)
}

Message represents a message to be sent over the network. It is the data type of the stdevents.SendMessage.Payload and stdevents.MessageReceived.Payload. The only requirement of a Message is that it must be serializable. Note that while a stdevents.SendMessage event as well as a stdevents.MessageReceived event can contain an arbitrary implementation of this interface in their Payload fields, a SendMessage or a MessageReceived event that underwent serialization and deserialization will always contain the RawMessage implementation of this interface, only holding the serialized representation of the original message. This is because Mir does not by itself know how to deserialize arbitrary (application-specific) messages.

type ModuleID

type ModuleID string

ModuleID represents an identifier of a module. The intention is for it to correspond to a path in the module hierarchy. However, technically, the Mir Node only cares for the ID's prefix up to the first separator and ignores the rest. The rest of the ID can be used for any module-specific purposes.

func (ModuleID) String

func (mid ModuleID) String() string

func (ModuleID) Sub

func (mid ModuleID) Sub() ModuleID

Sub returns the identifier of a submodule within the top-level module, stripped of the top-level module identifier.

func (ModuleID) Then

func (mid ModuleID) Then(submodule ModuleID) ModuleID

Then combines the module ID with a relative path to its submodule in a single module ID.

func (ModuleID) Top

func (mid ModuleID) Top() ModuleID

Top returns the ID of the top-level module of the path, stripped of the IDs of the submodules.

type NodeAddress

type NodeAddress multiaddr.Multiaddr

NodeAddress represents the address of a node.

func NodeAddressFromString

func NodeAddressFromString(addrString string) (NodeAddress, error)

type NodeID

type NodeID string

NodeID represents the ID of a node.

func NewNodeIDFromInt

func NewNodeIDFromInt(id int) NodeID

func NodeIDSlice

func NodeIDSlice(nids []string) []NodeID

NodeIDSlice converts a slice of NodeIDs represented directly as their underlying native type to a slice of abstractly typed node IDs.

func (NodeID) Bytes

func (id NodeID) Bytes() []byte

Bytes returns the byte slice representation of the node ID.

type RawData

type RawData []byte

RawData represents raw data contained in a deserialized event. When an event from the stdevents package undergoes serialization and deserialization, application-specific data types (represented by the Serializable type) are represented as RawData. In this form, they are handed over to application-specific code which is responsible for its deserialization.

func (RawData) String

func (d RawData) String() string

func (RawData) ToBytes

func (d RawData) ToBytes() ([]byte, error)

type RawMessage

type RawMessage RawData

RawMessage is technically just raw data (RawData). We use a separate type to distinguish data that is intended to be sent/received over the network from data that is generated and used locally. The difference is important for making assumptions on the consistency / correctness of the data.

func (RawMessage) ToBytes

func (rm RawMessage) ToBytes() ([]byte, error)

ToBytes just delegates the call to the underlying type.

type RetentionIndex

type RetentionIndex uint64

RetentionIndex represents an abstract notion of system progress used in garbage collection. The basic idea is to associate various parts of the system (parts of the state, even whole modules) that are subject to eventual garbage collection with a retention index. As the system progresses, the retention index monotonically increases and parts of the system associated with a lower retention index can be garbage-collected.

type Serializable

type Serializable interface {
	ToBytes() ([]byte, error)
}

Serializable is the type used for certain application-specific objects included in some standard events (stdevents). For example, the parameters to a submodule are required to be serializable. When deserializing events from the stdevents package, such objects will deserialize to RawData.

Jump to

Keyboard shortcuts

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