message

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 8 Imported by: 16

Documentation

Overview

Package message provides utilities for representing information about Dogma messages and their use within an application.

Index

Constants

This section is empty.

Variables

Roles is a slice of the valid message roles.

Functions

func IsEqualSetN added in v0.7.1

func IsEqualSetN(a, b NameCollection) bool

IsEqualSetN returns true if a and b are equal.

That is, it returns true if and only if every element of a is an element of b, and vice-versa.

func IsEqualSetT added in v0.7.1

func IsEqualSetT(a, b TypeCollection) bool

IsEqualSetT returns true if a and b are equal.

That is, it returns true if and only if every element of a is an element of b, and vice-versa.

func IsIntersectingN added in v0.2.2

func IsIntersectingN(a, b NameCollection) bool

IsIntersectingN returns true if a and b are intersecting.

That is, it returns true if a and b contain any of the same names.

See https://en.wikipedia.org/wiki/Set_(mathematics)#Intersections.

func IsIntersectingT added in v0.2.2

func IsIntersectingT(a, b TypeCollection) bool

IsIntersectingT returns true if a and b are intersecting.

That is, it returns true if a and b contain any of the same types.

See https://en.wikipedia.org/wiki/Set_(mathematics)#Intersections.

func IsSubsetN added in v0.2.2

func IsSubsetN(sub, sup NameCollection) bool

IsSubsetN returns true if sub is a (non-strict) subset of sup.

That is, it returns true if sup contains all of the names in sub.

See https://en.wikipedia.org/wiki/Set_(mathematics)#Subsets.

func IsSubsetT added in v0.2.2

func IsSubsetT(sub, sup TypeCollection) bool

IsSubsetT returns true if sub is a (non-strict) subset of sup.

That is, it returns true if sup contains all of the types in sub.

See https://en.wikipedia.org/wiki/Set_(mathematics)#Subsets.

Types

type Name

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

Name is the fully-qualified name of a message type.

func NameFromType added in v0.10.0

func NameFromType(t types.Type) Name

NameFromType returns the fully-qualified type name of t.

func NameOf

func NameOf(m dogma.Message) Name

NameOf returns the fully-qualified type name of v.

func (Name) IsZero

func (n Name) IsZero() bool

IsZero returns true if n is the zero-value.

func (Name) MarshalBinary

func (n Name) MarshalBinary() ([]byte, error)

MarshalBinary returns a binary representation of the name.

func (Name) MarshalText

func (n Name) MarshalText() ([]byte, error)

MarshalText returns a UTF-8 representation of the name.

func (Name) String

func (n Name) String() string

String returns the fully-qualified type name as a string.

func (*Name) UnmarshalBinary

func (n *Name) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a type from its binary representation.

func (*Name) UnmarshalText

func (n *Name) UnmarshalText(text []byte) error

UnmarshalText unmarshals a name from its UTF-8 representation.

type NameCollection

type NameCollection interface {
	// Has returns true if n is in the container.
	Has(n Name) bool

	// HasM returns true if NameOf(m) is in the container.
	HasM(m dogma.Message) bool

	// Len returns the number of names in the collection.
	Len() int

	// Range invokes fn once for each name in the container.
	//
	// Iteration stops when fn returns false or once fn has been invoked for all
	// names in the container.
	//
	// It returns true if fn returned true for all names.
	Range(fn func(Name) bool) bool
}

NameCollection is an interface for containers of message names.

type NameRoles

type NameRoles map[Name]Role

NameRoles is an implementation of NameCollection that maps message types to their roles.

func (NameRoles) Add

func (nr NameRoles) Add(n Name, r Role) bool

Add maps n to r.

It returns true if the mapping was added, or false if the map already contained the name.

func (NameRoles) AddM

func (nr NameRoles) AddM(m dogma.Message, r Role) bool

AddM adds NameOf(m) to nr.

It returns true if the mapping was added, or false if the map already contained the name.

func (NameRoles) FilterByRole added in v0.7.0

func (nr NameRoles) FilterByRole(r Role) NameRoles

FilterByRole returns the subset of names that have the given role.

func (NameRoles) Has

func (nr NameRoles) Has(n Name) bool

Has returns true if nr contains n.

func (NameRoles) HasM

func (nr NameRoles) HasM(m dogma.Message) bool

HasM returns true if nr contains NameOf(m).

func (NameRoles) IsEqual added in v0.2.0

func (nr NameRoles) IsEqual(o NameRoles) bool

IsEqual returns true if o contains the same names with the same roles as s.

func (NameRoles) Len added in v0.7.2

func (nr NameRoles) Len() int

Len returns the number of names in the collection.

func (NameRoles) Range added in v0.3.0

func (nr NameRoles) Range(fn func(Name) bool) bool

Range invokes fn once for each name in the container.

Iteration stops when fn returns false or once fn has been invoked for all names in the container.

It returns true if fn returned true for all names.

func (NameRoles) RangeByRole added in v0.7.0

func (nr NameRoles) RangeByRole(
	r Role,
	fn func(Name) bool,
) bool

RangeByRole invokes fn once for each name in the container that maps to the given role.

Iteration stops when fn returns false or once fn has been invoked for all names in the container.

It returns true if fn returned true for all names.

func (NameRoles) Remove

func (nr NameRoles) Remove(n Name) bool

Remove removes n from nr.

It returns true if the name was removed, or false if the set did not contain the name.

func (NameRoles) RemoveM

func (nr NameRoles) RemoveM(m dogma.Message) bool

RemoveM removes NameOf(m) from nr.

It returns true if the name was removed, or false if the set did not contain the name.

type NameSet

type NameSet map[Name]struct{}

NameSet is an implementation of NameCollection that contains a distinct set of message names.

func DiffN added in v0.2.2

func DiffN(a, b NameCollection) NameSet

DiffN returns the difference between a and b.

That is, it returns a set containing all of the names present in a that are not present in b.

See https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement.

func IntersectionN added in v0.2.2

func IntersectionN(collections ...NameCollection) NameSet

IntersectionN returns the intersection of the given collections.

That is, it returns a set containing only those names that are present in all of the given collections. It returns an empty set if no collections are given.

See https://en.wikipedia.org/wiki/Intersection_(set_theory).

func NamesOf

func NamesOf(messages ...dogma.Message) NameSet

NamesOf returns a name set containing the names of the given messages.

func NewNameSet

func NewNameSet(names ...Name) NameSet

NewNameSet returns a NameSet containing the given names.

func UnionN added in v0.2.2

func UnionN(collections ...NameCollection) NameSet

UnionN returns the union of the given collections.

That is, it returns a set containing all of the names present in all of the given collections. It returns an empty set if no collections are given.

See https://en.wikipedia.org/wiki/Union_(set_theory).

func (NameSet) Add

func (s NameSet) Add(n Name) bool

Add adds n to s.

It returns true if the name was added, or false if the set already contained the name.

func (NameSet) AddM

func (s NameSet) AddM(m dogma.Message) bool

AddM adds NameOf(m) to s.

It returns true if the name was added, or false if the set already contained the name.

func (NameSet) Has

func (s NameSet) Has(n Name) bool

Has returns true if s contains n.

func (NameSet) HasM

func (s NameSet) HasM(m dogma.Message) bool

HasM returns true if s contains NameOf(m).

func (NameSet) IsEqual added in v0.2.0

func (s NameSet) IsEqual(o NameSet) bool

IsEqual returns true if o contains the same names as s.

func (NameSet) Len added in v0.7.2

func (s NameSet) Len() int

Len returns the number of names in the collection.

func (NameSet) Range added in v0.3.0

func (s NameSet) Range(fn func(Name) bool) bool

Range invokes fn once for each name in the container.

Iteration stops when fn returns false or once fn has been invoked for all names in the container.

It returns true if fn returned true for all names.

func (NameSet) Remove

func (s NameSet) Remove(n Name) bool

Remove removes n from s.

It returns true if the name was removed, or false if the set did not contain the name.

func (NameSet) RemoveM

func (s NameSet) RemoveM(m dogma.Message) bool

RemoveM removes NameOf(m) from s.

It returns true if the name was removed, or false if the set did not contain the name.

type Role

type Role string

Role is an enumeration of the roles a message can perform within an application.

const (
	// CommandRole is the role for command messages.
	CommandRole Role = "command"

	// EventRole is the role for event messages.
	EventRole Role = "event"

	// TimeoutRole is the role for timeout messages.
	TimeoutRole Role = "timeout"
)

func (Role) Is

func (r Role) Is(roles ...Role) bool

Is returns true if r is one of the given roles.

func (Role) Marker

func (r Role) Marker() string

Marker returns a character that identifies the message role when displaying message types.

func (Role) MarshalBinary

func (r Role) MarshalBinary() ([]byte, error)

MarshalBinary returns a binary representation of the message role.

func (Role) MarshalText

func (r Role) MarshalText() ([]byte, error)

MarshalText returns a UTF-8 representation of the message role.

func (Role) MustBe

func (r Role) MustBe(roles ...Role)

MustBe panics if r is not one of the given roles.

func (Role) MustNotBe

func (r Role) MustNotBe(roles ...Role)

MustNotBe panics if r is one of the given roles.

func (Role) MustValidate

func (r Role) MustValidate()

MustValidate panics if r is not a valid message role.

func (Role) ShortString

func (r Role) ShortString() string

ShortString returns a short (3-character) representation of the handler type.

func (Role) String

func (r Role) String() string

func (*Role) UnmarshalBinary

func (r *Role) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a role from its binary representation.

func (*Role) UnmarshalText

func (r *Role) UnmarshalText(text []byte) error

UnmarshalText unmarshals a role from its UTF-8 representation.

func (Role) Validate

func (r Role) Validate() error

Validate return an error if r is not a valid message role.

type Type

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

Type represents the type of a Dogma message.

func TypeFromReflect added in v0.4.1

func TypeFromReflect(rt reflect.Type) Type

TypeFromReflect returns the message type of the given reflect type.

func TypeOf

func TypeOf(m dogma.Message) Type

TypeOf returns the message type of m.

func (Type) IsZero

func (t Type) IsZero() bool

IsZero returns true if t is the zero-value.

func (Type) Name

func (t Type) Name() Name

Name returns the fully-qualified name for the Go type.

It panics if t.IsZero() returns true.

func (Type) ReflectType

func (t Type) ReflectType() reflect.Type

ReflectType returns the reflect.Type of the message.

It panics if t.IsZero() returns true.

func (Type) String

func (t Type) String() string

String returns a human-readable name for the type.

The returned name is not necessarily globally-unique.

type TypeCollection

type TypeCollection interface {
	// Has returns true if t is in the container.
	Has(t Type) bool

	// HasM returns true if TypeOf(m) is in the container.
	HasM(m dogma.Message) bool

	// Len returns the number of names in the collection.
	Len() int

	// Range invokes fn once for each type in the container.
	//
	// Iteration stops when fn returns false or once fn has been invoked for all
	// types in the container.
	//
	// It returns true if fn returned true for all types.
	Range(fn func(Type) bool) bool
}

TypeCollection is an interface for containers of message types.

type TypeRoles

type TypeRoles map[Type]Role

TypeRoles is an implementation of TypeCollection that maps message types to their roles.

func (TypeRoles) Add

func (tr TypeRoles) Add(t Type, r Role) bool

Add maps t to r.

It returns true if the mapping was added, or false if the map already contained the type.

func (TypeRoles) AddM

func (tr TypeRoles) AddM(m dogma.Message, r Role) bool

AddM adds TypeOf(m) to tr.

It returns true if the mapping was added, or false if the map already contained the type.

func (TypeRoles) FilterByRole added in v0.7.0

func (tr TypeRoles) FilterByRole(r Role) TypeRoles

FilterByRole returns the subset of types that have the given role.

func (TypeRoles) Has

func (tr TypeRoles) Has(t Type) bool

Has returns true if tr contains t.

func (TypeRoles) HasM

func (tr TypeRoles) HasM(m dogma.Message) bool

HasM returns true if tr contains TypeOf(m).

func (TypeRoles) IsEqual added in v0.2.0

func (tr TypeRoles) IsEqual(o TypeRoles) bool

IsEqual returns true if o contains the same types with the same roles as tr.

func (TypeRoles) Len added in v0.7.2

func (tr TypeRoles) Len() int

Len returns the number of types in the collection.

func (TypeRoles) Range added in v0.3.0

func (tr TypeRoles) Range(fn func(Type) bool) bool

Range invokes fn once for each type in the container.

Iteration stops when fn returns false or once fn has been invoked for all types in the container.

It returns true if fn returned true for all types.

func (TypeRoles) RangeByRole added in v0.7.0

func (tr TypeRoles) RangeByRole(
	r Role,
	fn func(Type) bool,
) bool

RangeByRole invokes fn once for each type in the container that maps to the given role.

Iteration stops when fn returns false or once fn has been invoked for all types in the container.

It returns true if fn returned true for all types.

func (TypeRoles) Remove

func (tr TypeRoles) Remove(t Type) bool

Remove removes t from tr.

It returns true if the type was removed, or false if the set did not contain the type.

func (TypeRoles) RemoveM

func (tr TypeRoles) RemoveM(m dogma.Message) bool

RemoveM removes TypeOf(m) from tr.

It returns true if the type was removed, or false if the set did not contain the type.

type TypeSet

type TypeSet map[Type]struct{}

TypeSet is an implementation of TypeCollection that contains a distinct set of message types.

func DiffT added in v0.2.2

func DiffT(a, b TypeCollection) TypeSet

DiffT returns the difference between a and b.

That is, it returns a set containing all of the types present in a that are not present in b.

See https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement.

func IntersectionT added in v0.2.2

func IntersectionT(collections ...TypeCollection) TypeSet

IntersectionT returns the intersection of the given collections.

That is, it returns a set containing only those types that are present in all of the given collections. It returns an empty set if no collections are given.

See https://en.wikipedia.org/wiki/Intersection_(set_theory).

func NewTypeSet

func NewTypeSet(types ...Type) TypeSet

NewTypeSet returns a TypeSet containing the given types.

func TypesOf

func TypesOf(messages ...dogma.Message) TypeSet

TypesOf returns a type set containing the types of the given messages.

func UnionT added in v0.2.2

func UnionT(collections ...TypeCollection) TypeSet

UnionT returns the union of the given collections.

That is, it returns a set containing all of the types present in all of the given collections. It returns an empty set if no collections are given.

See https://en.wikipedia.org/wiki/Union_(set_theory).

func (TypeSet) Add

func (s TypeSet) Add(t Type) bool

Add adds t to s.

It returns true if the type was added, or false if the set already contained the type.

func (TypeSet) AddM

func (s TypeSet) AddM(m dogma.Message) bool

AddM adds TypeOf(m) to s.

It returns true if the type was added, or false if the set already contained the type.

func (TypeSet) Has

func (s TypeSet) Has(t Type) bool

Has returns true if s contains t.

func (TypeSet) HasM

func (s TypeSet) HasM(m dogma.Message) bool

HasM returns true if s contains TypeOf(m).

func (TypeSet) IsEqual added in v0.2.0

func (s TypeSet) IsEqual(o TypeSet) bool

IsEqual returns true if o contains the same types as s.

func (TypeSet) Len added in v0.7.2

func (s TypeSet) Len() int

Len returns the number of types in the collection.

func (TypeSet) Range added in v0.3.0

func (s TypeSet) Range(fn func(Type) bool) bool

Range invokes fn once for each type in the container.

Iteration stops when fn returns false or once fn has been invoked for all types in the container.

It returns true if fn returned true for all types.

func (TypeSet) Remove

func (s TypeSet) Remove(t Type) bool

Remove removes t from s.

It returns true if the type was removed, or false if the set did not contain the type.

func (TypeSet) RemoveM

func (s TypeSet) RemoveM(m dogma.Message) bool

RemoveM removes TypeOf(m) from s.

It returns true if the type was removed, or false if the set did not contain the type.

Jump to

Keyboard shortcuts

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