utils

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DependsOn

func DependsOn(k1, k2 string, deps map[string]KeySet, visited KeySet) bool

DependsOn returns true if k1 depends on k2 based on dependencies from <deps>.

func ErrorToString

func ErrorToString(err error) string

ErrorToString converts error to string.

func ProtoToString

func ProtoToString(msg proto.Message) string

ProtoToString converts proto message to string.

func TopologicalOrder

func TopologicalOrder(keys KeySet, deps map[string]KeySet, depFirst bool, handleCycle bool) (sorted []string)

TopologicalOrder orders keys topologically by Kahn's algorithm to respect the given dependencies. deps = map{ key -> <set of keys the given key depends on> }

Types

type KeySet

type KeySet interface {
	// String return human-readable string representation of the key-set.
	String() string

	// Iterate exposes the set of keys as slice which can be iterated through.
	// The returned slice should not be modified.
	Iterate() []string

	// Length returns the number of keys in the set.
	Length() int

	// Equals compares this set with <set2> for equality.
	Equals(set2 KeySet) bool

	// Has returns true if the given key is in the set.
	Has(key string) bool

	// Add adds key into the set.
	Add(key string) (changed bool)

	// Del removes key from the set.
	Del(key string) (changed bool)

	// Subtract removes keys from this set which are also in <ks2>.
	Subtract(ks2 KeySet) (changed bool)

	// Intersect removes keys from this set which are not in <ks2>.
	Intersect(ks2 KeySet) (changed bool)

	// CopyOnWrite returns first a shallow copy of the key set, which gets
	// deep-copied when it is about to get modified.
	CopyOnWrite() KeySet
}

KeySet defines API for a set of keys.

func NewMapBasedKeySet

func NewMapBasedKeySet(keys ...string) KeySet

NewMapBasedKeySet returns KeySet implemented using map.

func NewSingletonKeySet

func NewSingletonKeySet(key string) KeySet

NewSingletonKeySet returns KeySet implementation for at most one key.

func NewSliceBasedKeySet

func NewSliceBasedKeySet(keys ...string) KeySet

NewSliceBasedKeySet returns KeySet implemented using a slice with ordered keys.

type ProtoWithName

type ProtoWithName struct {
	ProtoMsgName string
	ProtoMsgData string
}

ProtoWithName is used to marshall proto message data alongside the proto message name.

type RecordedProtoMessage

type RecordedProtoMessage struct {
	proto.Message
	ProtoMsgName string
}

RecordedProtoMessage is a proto.Message suitable for recording and access via REST API.

func RecordProtoMessage

func RecordProtoMessage(msg proto.Message) *RecordedProtoMessage

RecordProtoMessage prepares proto message for recording and potential access via REST API. Note: no need to clone the message - once un-marshalled, the content is never changed (otherwise it would break prev-new value comparisons).

func (*RecordedProtoMessage) MarshalJSON

func (p *RecordedProtoMessage) MarshalJSON() ([]byte, error)

MarshalJSON marshalls proto message using the marshaller from jsonpb. The jsonpb package produces a different output than the standard "encoding/json" package, which does not operate correctly on protocol buffers.

func (*RecordedProtoMessage) UnmarshalJSON

func (p *RecordedProtoMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON un-marshalls proto message using the marshaller from jsonpb. The jsonpb package produces a different output than the standard "encoding/json" package, which does not operate correctly on protocol buffers.

Jump to

Keyboard shortcuts

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