prototransform

package module
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 11 Imported by: 0

README

proto-transform

A small go-lang library that accepts proto file message definitions in protofbuf serialisation format (see proto target in Makefile for how to create these) and a message mapping and allows transformation from one message to another purely off of these mappings.


Usage

transform_test.go has test cases illustrating usage but in brief

fileDescriptorProto, _ := os.ReadFile("models.pb")
messageMappings := map[string]map[string]string{
		"WorkflowState-Compensation": {
			"unixTimeNano": "totalSteps",
			"elementName":  "forTrackingId",
			"timer.lastFired": "step",
		},
	}

transformer, _ := NewTransformer(messageMappings, fileDescriptorProto) // can take multiple fileDescriptor proto files

compensationProtoMessage, err := transform.Transform(workflowStateProtoMessage, "Compensation")

Roadmap

potential improvements:

  • the module supports transformations of nested message structures but not nested map or list structures. This might be worth implementing after considering if there are valid use cases.
  • add support for golang contexts. The initial cut does not accept a ctx and any of its benefits (like exiting execution on done signal).

License

see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	// contains filtered or unexported methods
}

type ActionResult

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

type Get

type Get struct{}

type Set

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

type Transformer

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

func NewTransformer

func NewTransformer(messageMappings map[string]map[string]string, fileDescriptorProtos ...[]byte) (Transformer, error)

func (Transformer) Transform

func (t Transformer) Transform(ctx context.Context, f proto.Message, toMessageName string) (proto.Message, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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