decoding

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware added in v0.2.0

func Middleware(target appdata.Listener, resolver DecoderResolver, opts MiddlewareOptions) (appdata.Listener, error)

Middleware decodes raw data passed to the listener as kv-updates into decoded object updates. Module initialization is done lazily as modules are encountered in the kv-update stream.

func Sync added in v0.2.0

func Sync(listener appdata.Listener, source SyncSource, resolver DecoderResolver, opts SyncOptions) error

Sync synchronizes existing state from the sync source to the listener using the resolver to decode data.

Types

type DecoderResolver

type DecoderResolver interface {
	// DecodeModuleName decodes a module name from a byte slice passed as the actor in a KVPairUpdate.
	DecodeModuleName([]byte) (string, error)

	// EncodeModuleName encodes a module name into a byte slice that can be used as the actor in a KVPairUpdate.
	EncodeModuleName(string) ([]byte, error)

	// IterateAll iterates over all available module decoders.
	IterateAll(func(moduleName string, cdc schema.ModuleCodec) error) error

	// LookupDecoder looks up a specific module decoder.
	LookupDecoder(moduleName string) (decoder schema.ModuleCodec, found bool, err error)
}

DecoderResolver is an interface that allows indexers to discover and use module decoders.

func ModuleSetDecoderResolver

func ModuleSetDecoderResolver(moduleSet map[string]interface{}) DecoderResolver

ModuleSetDecoderResolver returns DecoderResolver that will discover modules implementing DecodeableModule in the provided module set.

type MiddlewareOptions added in v0.2.0

type MiddlewareOptions struct {
	ModuleFilter func(moduleName string) bool
}

type SyncOptions added in v0.2.0

type SyncOptions struct {
	ModuleFilter func(moduleName string) bool
}

SyncOptions are the options for Sync.

type SyncSource

type SyncSource interface {
	// IterateAllKVPairs iterates over all key-value pairs for a given module.
	IterateAllKVPairs(moduleName string, fn func(key, value []byte) error) error
}

SyncSource is an interface that allows indexers to start indexing modules with pre-existing state. It should generally be a wrapper around the key-value store.

Jump to

Keyboard shortcuts

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