utils

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NonceLength is the length of the string returned by NewNonce. NewNonce encodes the current UNIX
	// time in nanos and the remaining chunks, encoded as 64-bit and 32-bit integers respectively, then
	// hex encoded. This means a nonce will always be 8 + 4 bytes, multiplied by 2 by the hex encoding.
	NonceLength = (8 + 4) * 2
)

Variables

This section is empty.

Functions

func GetTypeURL

func GetTypeURL[T proto.Message]() string

func IsPseudoDeltaSotW

func IsPseudoDeltaSotW(typeURL string) bool

IsPseudoDeltaSotW checks whether the given resource type url is intended to behave as a "pseudo delta" resource. Instead of sending the entire state of the world for every resource change, the server is expected to only send the changed resource. From the spec:

In the SotW protocol variants, all resource types except for Listener and Cluster are grouped into
responses in the same way as in the incremental protocol variants. However, Listener and Cluster
resource types are handled differently: the server must include the complete state of the world,
meaning that all resources of the relevant type that are needed by the client must be included,
even if they did not change since the last response.

In other words, for everything except Listener and Cluster, the server should only send the changed resources, rather than every resource every time.

func MapToProto

func MapToProto(m map[string]string) string

MapToProto serializes the given map using protobuf. It sorts the entries based on the key such that the same map always produces the same output. It then encodes the entries by appending the key then value, and b64 encodes the entire output. Note that the final b64 encoding step is critical as this function is intended to be used with [ads.SotWDiscoveryResponse.Version], which is a string field. In protobuf, string fields must contain valid UTF-8 characters, and b64 encoding ensures that.

func NewNonce

func NewNonce(remainingChunks int) string

NewNonce creates a new unique nonce based on the current UNIX time in nanos, always returning a string of NonceLength.

func ProtoToMap

func ProtoToMap(s string) (map[string]string, error)

ProtoToMap is the inverse of MapToProto. It returns an error on any decoding or deserialization issues.

func TrimTypeURL

func TrimTypeURL(typeURL string) string

TrimTypeURL removes the leading "types.googleapis.com/" prefix from the given string.

Types

type Set

type Set[T comparable] map[T]struct{}

func NewSet

func NewSet[T comparable](elements ...T) Set[T]

func (Set[T]) Add

func (s Set[T]) Add(t T) bool

func (Set[T]) Contains

func (s Set[T]) Contains(t T) bool

func (Set[T]) Remove

func (s Set[T]) Remove(t T) bool

func (Set[T]) String

func (s Set[T]) String() string

func (Set[T]) Values added in v0.2.0

func (s Set[T]) Values() iter.Seq[T]

Jump to

Keyboard shortcuts

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