transform

package
v0.0.0-...-7a622f3 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package transform contains the elements to be able to transform commands which consist of interfaces for individual transform operations and a transform chain to run all of them.

Package transform contains the elements to be able to transform commands which consist of interfaces for individual transform operations and a transform chain to run all of them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandID

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

func NewEndCommandID

func NewEndCommandID() CommandID

func NewTransformCommandID

func NewTransformCommandID(id api.CmdID) CommandID

func (*CommandID) GetCommandType

func (c *CommandID) GetCommandType() CommandType

func (*CommandID) GetID

func (c *CommandID) GetID() api.CmdID

func (*CommandID) Increment

func (c *CommandID) Increment()

type CommandType

type CommandType uint32
const (
	TransformCommand CommandType = 0
	EndCommand       CommandType = 1
)

func (CommandType) String

func (cmdType CommandType) String() string

type StateMutator

type StateMutator func(cmds []api.Cmd) error

StateMutator is a function that allows transformation to mutate state during transformation TODO: Refactor the transforms that use this to remove this behaviour

type Transform

type Transform interface {
	// BeginTransform is called before transforming any command.
	BeginTransform(ctx context.Context, inputState *api.GlobalState) error

	// EndTransform is called after all commands are transformed.
	EndTransform(ctx context.Context, inputState *api.GlobalState) ([]api.Cmd, error)

	// TransformCommand takes a given command list and a state.
	// It outputs a new set of commands after running the transformation.
	// Transforms must not modify the input commands:
	// they can add or remove commands in the command list,
	// but they must not edit the internals of the commands that they receive as input.
	TransformCommand(ctx context.Context, id CommandID, inputCommands []api.Cmd, inputState *api.GlobalState) ([]api.Cmd, error)

	// ClearTransformResources releases the resources that have been allocated during transform
	// Resources are needed for the state mutation, therefore this should be called after mutation.
	ClearTransformResources(ctx context.Context)

	// RequiresAccurateState returns true if the transform needs to observe the accurate state.
	RequiresAccurateState() bool

	// RequiresInnerStateMutation returns true if the transform needs to mutate state during the transformation
	RequiresInnerStateMutation() bool

	// SetInnerStateMutationFunction sets a mutator function for making a branch in the transform
	// to transform and mutate pending commands to be able to continue transform.
	SetInnerStateMutationFunction(stateMutator StateMutator)
}

Transform is the interface that wraps the basic Transform functionality. Implementers of this interface, should take a list of commands and a state so they can do the necessary operations with them to achieve the results they aim to do and emit a list of commands to pass it to the next transform.

type TransformChain

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

TransformChain is responsible for running all the transforms on all the commands produced by command enerator

func CreateTransformChain

func CreateTransformChain(ctx context.Context, generator commandGenerator.CommandGenerator, transforms []Transform, out Writer) *TransformChain

CreateTransformChain creates a transform chain that will run the required transforms on every command coming from commandGenerator

func (*TransformChain) GetCurrentCommandID

func (chain *TransformChain) GetCurrentCommandID() CommandID

func (*TransformChain) GetNumOfRemainingCommands

func (chain *TransformChain) GetNumOfRemainingCommands() uint64

func (*TransformChain) IsEndOfCommands

func (chain *TransformChain) IsEndOfCommands() bool

func (*TransformChain) ProcessNextTransformedCommands

func (chain *TransformChain) ProcessNextTransformedCommands(ctx context.Context) ([]api.Cmd, error)

func (*TransformChain) State

func (chain *TransformChain) State() *api.GlobalState

type Writer

type Writer interface {
	// State returns the state object associated with this writer.
	State() *api.GlobalState
	// MutateAndWrite mutates the state object associated with this writer,
	// and it passes the command to further consumers.
	MutateAndWrite(ctx context.Context, id api.CmdID, cmd api.Cmd) error
}

Writer is the interface which consumes the output of transforms. MutateAndWrite function in this interface will be called either when any transform needs an accurate state or after the all transforms have been processed for a certain command. This interface can be used when it is necessary to collect the results of the transforms e.g. to build instructions for gapir. Implementers of this interface should provide a state function that returns the global state and a MutateAndWrite method to acknowledge the current command that has been processed.

Jump to

Keyboard shortcuts

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