converter

package
Version: v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 11 Imported by: 19

Documentation

Index

Constants

View Source
const (
	// MetadataEncoding is "encoding"
	MetadataEncoding = "encoding"
	// MetadataEncodingBinary is "binary/plain"
	MetadataEncodingBinary = "binary/plain"
	// MetadataEncodingJSON is "json/plain"
	MetadataEncodingJSON = "json/plain"
	// MetadataEncodingNil is "binary/null"
	MetadataEncodingNil = "binary/null"
	// MetadataEncodingProtoJSON is "json/protobuf"
	MetadataEncodingProtoJSON = "json/protobuf"
	// MetadataEncodingProto is "binary/protobuf"
	MetadataEncodingProto = "binary/protobuf"
)

Variables

View Source
var (
	// ErrMetadataIsNotSet is returned when metadata is not set.
	ErrMetadataIsNotSet = errors.New("metadata is not set")
	// ErrEncodingIsNotSet is returned when payload encoding metadata is not set.
	ErrEncodingIsNotSet = errors.New("payload encoding metadata is not set")
	// ErrEncodingIsNotSupported is returned when payload encoding is not supported.
	ErrEncodingIsNotSupported = errors.New("payload encoding is not supported")
	// ErrUnableToEncode is returned when unable to encode.
	ErrUnableToEncode = errors.New("unable to encode")
	// ErrUnableToDecode is returned when unable to decode.
	ErrUnableToDecode = errors.New("unable to decode")
	// ErrUnableToSetValue is returned when unable to set value.
	ErrUnableToSetValue = errors.New("unable to set value")
	// ErrUnableToFindConverter is returned when unable to find converter.
	ErrUnableToFindConverter = errors.New("unable to find converter")
	// ErrTypeNotImplementProtoMessage is returned when value doesn't implement proto.Message.
	ErrTypeNotImplementProtoMessage = errors.New("type doesn't implement proto.Message")
	// ErrValuePtrIsNotPointer is returned when proto value is not a pointer.
	ErrValuePtrIsNotPointer = errors.New("not a pointer type")
	// ErrValuePtrMustConcreteType is returned when proto value is of interface type.
	ErrValuePtrMustConcreteType = errors.New("must be a concrete type, not interface")
)

Functions

This section is empty.

Types

type ByteSlicePayloadConverter

type ByteSlicePayloadConverter struct {
}

ByteSlicePayloadConverter pass through []byte to Data field in payload.

func NewByteSlicePayloadConverter

func NewByteSlicePayloadConverter() *ByteSlicePayloadConverter

NewByteSlicePayloadConverter creates new instance of ByteSlicePayloadConverter.

func (*ByteSlicePayloadConverter) Encoding

func (c *ByteSlicePayloadConverter) Encoding() string

Encoding returns MetadataEncodingBinary.

func (*ByteSlicePayloadConverter) FromPayload

func (c *ByteSlicePayloadConverter) FromPayload(payload *commonpb.Payload, valuePtr interface{}) error

FromPayload converts single []byte value from payload.

func (*ByteSlicePayloadConverter) ToPayload

func (c *ByteSlicePayloadConverter) ToPayload(value interface{}) (*commonpb.Payload, error)

ToPayload converts single []byte value to payload.

func (*ByteSlicePayloadConverter) ToString

func (c *ByteSlicePayloadConverter) ToString(payload *commonpb.Payload) string

ToString converts payload object into human readable string.

type CompositeDataConverter

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

CompositeDataConverter applies PayloadConverters in specified order.

func (*CompositeDataConverter) FromPayload

func (dc *CompositeDataConverter) FromPayload(payload *commonpb.Payload, valuePtr interface{}) error

FromPayload converts single value from payload.

func (*CompositeDataConverter) FromPayloads

func (dc *CompositeDataConverter) FromPayloads(payloads *commonpb.Payloads, valuePtrs ...interface{}) error

FromPayloads converts to a list of values of different types.

func (*CompositeDataConverter) ToPayload

func (dc *CompositeDataConverter) ToPayload(value interface{}) (*commonpb.Payload, error)

ToPayload converts single value to payload.

func (*CompositeDataConverter) ToPayloads

func (dc *CompositeDataConverter) ToPayloads(values ...interface{}) (*commonpb.Payloads, error)

ToPayloads converts a list of values.

func (*CompositeDataConverter) ToString

func (dc *CompositeDataConverter) ToString(payload *commonpb.Payload) string

ToString converts payload object into human readable string.

func (*CompositeDataConverter) ToStrings

func (dc *CompositeDataConverter) ToStrings(payloads *commonpb.Payloads) []string

ToStrings converts payloads object into human readable strings.

type DataConverter

type DataConverter interface {
	// ToPayload converts single value to payload.
	ToPayload(value interface{}) (*commonpb.Payload, error)
	// FromPayload converts single value from payload.
	FromPayload(payload *commonpb.Payload, valuePtr interface{}) error

	// ToPayloads converts a list of values.
	ToPayloads(value ...interface{}) (*commonpb.Payloads, error)
	// FromPayloads converts to a list of values of different types.
	// Useful for deserializing arguments of function invocations.
	FromPayloads(payloads *commonpb.Payloads, valuePtrs ...interface{}) error

	// ToString converts payload object into human readable string.
	ToString(input *commonpb.Payload) string
	// ToStrings converts payloads object into human readable strings.
	ToStrings(input *commonpb.Payloads) []string
}

DataConverter is used by the framework to serialize/deserialize input and output of activity/workflow that need to be sent over the wire. To encode/decode workflow arguments, set DataConverter in client, through client.Options. To override DataConverter for specific activity or child workflow use workflow.WithDataConverter to create new Context, and pass that context to ExecuteActivity/ExecuteChildWorkflow calls. Temporal support using different DataConverters for different activity/childWorkflow in same workflow.

func GetDefaultDataConverter

func GetDefaultDataConverter() DataConverter

GetDefaultDataConverter returns default data converter used by Temporal worker.

func NewCompositeDataConverter

func NewCompositeDataConverter(payloadConverters ...PayloadConverter) DataConverter

NewCompositeDataConverter creates new instance of CompositeDataConverter from ordered list of PayloadConverters. Order is important here because during serialization DataConverter will try PayloadsConverters in that order until PayloadConverter returns non nil payload. Last PayloadConverter should always serialize the value (JSONPayloadConverter is good candidate for it).

type EncodedValue

type EncodedValue interface {
	// HasValue return whether there is value encoded.
	HasValue() bool
	// Get extract the encoded value into strong typed value pointer.
	Get(valuePtr interface{}) error
}

EncodedValue is used to encapsulate/extract encoded value from workflow/activity.

type EncodedValues

type EncodedValues interface {
	// HasValues return whether there are values encoded.
	HasValues() bool
	// Get extract the encoded values into strong typed value pointers.
	Get(valuePtr ...interface{}) error
}

EncodedValues is used to encapsulate/extract encoded one or more values from workflow/activity.

type JSONPayloadConverter

type JSONPayloadConverter struct {
}

JSONPayloadConverter converts to/from JSON.

func NewJSONPayloadConverter

func NewJSONPayloadConverter() *JSONPayloadConverter

NewJSONPayloadConverter creates new instance of JSONPayloadConverter.

func (*JSONPayloadConverter) Encoding

func (c *JSONPayloadConverter) Encoding() string

Encoding returns MetadataEncodingJSON.

func (*JSONPayloadConverter) FromPayload

func (c *JSONPayloadConverter) FromPayload(payload *commonpb.Payload, valuePtr interface{}) error

FromPayload converts single value from payload.

func (*JSONPayloadConverter) ToPayload

func (c *JSONPayloadConverter) ToPayload(value interface{}) (*commonpb.Payload, error)

ToPayload converts single value to payload.

func (*JSONPayloadConverter) ToString

func (c *JSONPayloadConverter) ToString(payload *commonpb.Payload) string

ToString converts payload object into human readable string.

type NilPayloadConverter

type NilPayloadConverter struct {
}

NilPayloadConverter doesn't set Data field in payload.

func NewNilPayloadConverter

func NewNilPayloadConverter() *NilPayloadConverter

NewNilPayloadConverter creates new instance of NilPayloadConverter.

func (*NilPayloadConverter) Encoding

func (c *NilPayloadConverter) Encoding() string

Encoding returns MetadataEncodingNil.

func (*NilPayloadConverter) FromPayload

func (c *NilPayloadConverter) FromPayload(_ *commonpb.Payload, valuePtr interface{}) error

FromPayload converts single nil value from payload.

func (*NilPayloadConverter) ToPayload

func (c *NilPayloadConverter) ToPayload(value interface{}) (*commonpb.Payload, error)

ToPayload converts single nil value to payload.

func (*NilPayloadConverter) ToString

ToString converts payload object into human readable string.

type PayloadConverter

type PayloadConverter interface {
	// ToPayload converts single value to payload. It should return nil if the PayloadConveter can not convert passed value (i.e. type is unknown).
	ToPayload(value interface{}) (*commonpb.Payload, error)
	// FromPayload converts single value from payload. valuePtr should be a reference to the variable of the type that is corresponding for payload encoding.
	// Otherwise it should return error.
	FromPayload(payload *commonpb.Payload, valuePtr interface{}) error
	// ToString converts payload object into human readable string.
	ToString(*commonpb.Payload) string

	// Encoding returns encoding supported by PayloadConverter.
	Encoding() string
}

PayloadConverter is an interface to convert a single payload.

type ProtoJSONPayloadConverter

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

ProtoJSONPayloadConverter converts proto objects to/from JSON.

func NewProtoJSONPayloadConverter

func NewProtoJSONPayloadConverter() *ProtoJSONPayloadConverter

NewProtoJSONPayloadConverter creates new instance of ProtoJSONPayloadConverter.

func (*ProtoJSONPayloadConverter) Encoding

func (c *ProtoJSONPayloadConverter) Encoding() string

Encoding returns MetadataEncodingProtoJSON.

func (*ProtoJSONPayloadConverter) FromPayload

func (c *ProtoJSONPayloadConverter) FromPayload(payload *commonpb.Payload, valuePtr interface{}) error

FromPayload converts single proto value from payload.

func (*ProtoJSONPayloadConverter) ToPayload

func (c *ProtoJSONPayloadConverter) ToPayload(value interface{}) (*commonpb.Payload, error)

ToPayload converts single proto value to payload.

func (*ProtoJSONPayloadConverter) ToString

func (c *ProtoJSONPayloadConverter) ToString(payload *commonpb.Payload) string

ToString converts payload object into human readable string.

type ProtoPayloadConverter

type ProtoPayloadConverter struct {
}

ProtoPayloadConverter converts proto objects to protobuf binary format.

func NewProtoPayloadConverter

func NewProtoPayloadConverter() *ProtoPayloadConverter

NewProtoPayloadConverter creates new instance of ProtoPayloadConverter.

func (*ProtoPayloadConverter) Encoding

func (c *ProtoPayloadConverter) Encoding() string

Encoding returns MetadataEncodingProto.

func (*ProtoPayloadConverter) FromPayload

func (c *ProtoPayloadConverter) FromPayload(payload *commonpb.Payload, valuePtr interface{}) error

FromPayload converts single proto value from payload.

func (*ProtoPayloadConverter) ToPayload

func (c *ProtoPayloadConverter) ToPayload(value interface{}) (*commonpb.Payload, error)

ToPayload converts single proto value to payload.

func (*ProtoPayloadConverter) ToString

func (c *ProtoPayloadConverter) ToString(payload *commonpb.Payload) string

ToString converts payload object into human readable string.

Jump to

Keyboard shortcuts

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