transformer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

Package transformer is an utility package designed to aid the process of taking a cast from a given input, applying a transformation to it and then outputting the transformed cast to somewhere.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Transformation

type Transformation interface {
	// Transform performs a mutation (in-place) in a cast.
	// note.: no concurrency mechanisms guarantee that this
	// is safe to be used across multiple goroutines
	Transform(c *cast.Cast) (err error)
}

Transformation describes a generic operation that is meant to mutate a single cast at a time.

type Transformer

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

Transformer wraps the agents in a tranformation pipeline. Once created (see `New`), whenever a transformation is meant to be performed (see `Transform`), `Transformer` will read a complete cast from `intput`, process it with the trasnformation set and then output the resulting cast to `output`.

We can illustrate the whole process like this:

input ==> transformation ==> output

Note.: `input` will be consumed until EOF before the transformation is applied.

func New

func New(t Transformation, input, output string) (m *Transformer, err error)

New instantiates a new Transformer instance.

The parameters are: - t: a Transformation interface implementor; - input: name of a file to read a cast from; and - output: name of a file to save the transformed cast to.

func (*Transformer) Close

func (m *Transformer) Close() (err error)

Close closes any open resources (input and output).

func (*Transformer) Transform

func (m *Transformer) Transform() (err error)

Transform performs the central piece of the cast transformation process: 1. decodes a cast from `input`; then 2. applies the transformation in the cast that now lives in memory; then 3. encodes the cast, saving it to `output`.

Jump to

Keyboard shortcuts

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