serde

package
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeySerde denotes a key Serde
	KeySerde = 1
	// ValueSerde denotes a value Serde
	ValueSerde = 2
)
View Source
const (
	// EnableValidation enables validation
	EnableValidation = true
	// DisableValidation disables validation
	DisableValidation = false
)
View Source
const (
	// TypeRecord represents a record
	TypeRecord = 1
	// TypeEnum represents an enum
	TypeEnum = 2
	// TypeArray represents an array
	TypeArray = 3
	// TypeMap represents a map
	TypeMap = 4
	// TypeCombined represents a combined
	TypeCombined = 5
	// TypeFixed represents a fixed
	TypeFixed = 6
	// TypeString represents a string
	TypeString = 7
	// TypeBytes represents bytes
	TypeBytes = 8
	// TypeInt represents an int
	TypeInt = 9
	// TypeLong represents a long
	TypeLong = 10
	// TypeFloat represents a float
	TypeFloat = 11
	// TypeDouble represents a double
	TypeDouble = 12
	// TypeBoolean represents a Boolean
	TypeBoolean = 13
	// TypeNull represents a null
	TypeNull = 14
)
View Source
const MagicByte byte = 0x0

MagicByte is prepended to the serialized payload

Variables

This section is empty.

Functions

func ClearRules

func ClearRules()

ClearRules clears all registered rules

func Expect

func Expect(actual, expected interface{}) error

Expect compares the actual and expected values

func RegisterRuleAction

func RegisterRuleAction(ruleAction RuleAction)

RegisterRuleAction is used to register a new rule action.

func RegisterRuleExecutor

func RegisterRuleExecutor(ruleExecutor RuleExecutor)

RegisterRuleExecutor is used to register a new rule executor.

func ResolveReferences

func ResolveReferences(c schemaregistry.Client, schema schemaregistry.SchemaInfo, deps map[string]string) error

ResolveReferences resolves schema references

func TopicNameStrategy

func TopicNameStrategy(topic string, serdeType Type, schema schemaregistry.SchemaInfo) (string, error)

TopicNameStrategy creates a subject name by appending -[key|value] to the topic name.

Types

type AbstractFieldRuleExecutor

type AbstractFieldRuleExecutor struct {
	FieldRuleExecutor
}

AbstractFieldRuleExecutor represents an abstract field rule executor

func (*AbstractFieldRuleExecutor) Transform

func (a *AbstractFieldRuleExecutor) Transform(ctx RuleContext, msg interface{}) (interface{}, error)

Transform transforms the message using the rule

type BaseDeserializer

type BaseDeserializer struct {
	Serde
	Conf *DeserializerConfig
}

BaseDeserializer represents basic deserializer info

func (*BaseDeserializer) ConfigureDeserializer

func (s *BaseDeserializer) ConfigureDeserializer(client schemaregistry.Client, serdeType Type,
	conf *DeserializerConfig) error

ConfigureDeserializer configures the Deserializer

func (*BaseDeserializer) GetReaderSchema

func (s *BaseDeserializer) GetReaderSchema(subject string) (*schemaregistry.SchemaMetadata, error)

GetReaderSchema returns a schema for reading

func (*BaseDeserializer) GetSchema

func (s *BaseDeserializer) GetSchema(topic string, payload []byte) (schemaregistry.SchemaInfo, error)

GetSchema returns a schema for a payload

type BaseSerializer

type BaseSerializer struct {
	Serde
	Conf *SerializerConfig
}

BaseSerializer represents basic serializer info

func (*BaseSerializer) ConfigureSerializer

func (s *BaseSerializer) ConfigureSerializer(client schemaregistry.Client, serdeType Type,
	conf *SerializerConfig) error

ConfigureSerializer configures the Serializer

func (*BaseSerializer) GetID

func (s *BaseSerializer) GetID(topic string, msg interface{}, info *schemaregistry.SchemaInfo) (int, error)

GetID returns a schema ID for the given schema

func (*BaseSerializer) WriteBytes

func (s *BaseSerializer) WriteBytes(id int, msgBytes []byte) ([]byte, error)

WriteBytes writes the serialized payload prepended by the MagicByte

type Deserializer

type Deserializer interface {
	ConfigureDeserializer(client schemaregistry.Client, serdeType Type,
		conf *DeserializerConfig) error
	// Deserialize will call the MessageFactory to create an object
	// into which we will unmarshal data.
	Deserialize(topic string, payload []byte) (interface{}, error)
	// DeserializeInto will unmarshal data into the given object.
	DeserializeInto(topic string, payload []byte, msg interface{}) error
	Close() error
}

Deserializer represents a deserializer

type DeserializerConfig

type DeserializerConfig struct {
	// UseLatestVersion specifies whether to use the latest schema version during deserialization
	UseLatestVersion bool
	// UseLatestWithMetadata specifies whether to use the latest schema with metadata during serialization
	UseLatestWithMetadata map[string]string
	// RuleConfig specifies configuration options to the rules
	RuleConfig map[string]string
}

DeserializerConfig is used to pass multiple configuration options to the deserializers.

func NewDeserializerConfig

func NewDeserializerConfig() *DeserializerConfig

NewDeserializerConfig returns a new configuration instance with sane defaults.

type ErrorAction

type ErrorAction struct {
}

ErrorAction represents an error action

func (ErrorAction) Close

func (a ErrorAction) Close() error

Close closes the action

func (ErrorAction) Configure

func (a ErrorAction) Configure(clientConfig *schemaregistry.Config, config map[string]string) error

Configure configures the action

func (ErrorAction) Run

func (a ErrorAction) Run(ctx RuleContext, msg interface{}, err error) error

Run runs the action

func (ErrorAction) Type

func (a ErrorAction) Type() string

Type returns the type

type FailFunc

type FailFunc func(string, ...error)

FailFunc is a function to call in case of failure

var MaybeFail FailFunc

MaybeFail represents a fail function

func InitFailFunc

func InitFailFunc(t *testing.T) FailFunc

InitFailFunc returns an initial fail function

func InitFailFuncBenchmark

func InitFailFuncBenchmark(b *testing.B) FailFunc

InitFailFuncBenchmark returns an initial fail function

type FieldContext

type FieldContext struct {
	ContainingMessage interface{}
	FullName          string
	Name              string
	Type              FieldType
	Tags              map[string]bool
}

FieldContext represents a field context

func (*FieldContext) IsPrimitive

func (f *FieldContext) IsPrimitive() bool

IsPrimitive returns true if the field is a primitive

func (*FieldContext) TypeName

func (f *FieldContext) TypeName() string

TypeName returns the type name

type FieldRuleExecutor

type FieldRuleExecutor interface {
	RuleExecutor
	NewTransform(ctx RuleContext) (FieldTransform, error)
}

FieldRuleExecutor represents a field rule executor

type FieldTransform

type FieldTransform interface {
	Transform(ctx RuleContext, fieldCtx FieldContext, fieldValue interface{}) (interface{}, error)
}

FieldTransform represents a field transform

type FieldTransformer

type FieldTransformer func(ctx RuleContext, fieldTransform FieldTransform, msg interface{}) (interface{}, error)

FieldTransformer represents a field transformer

type FieldType

type FieldType = int

FieldType represents the field type

type MessageFactory

type MessageFactory func(subject string, name string) (interface{}, error)

MessageFactory is a factory function, which should return a pointer to an instance into which we will unmarshal wire data. For Avro, the name will be the name of the Avro type if it has one. For JSON Schema, the name will be empty/F. For Protobuf, the name will be the name of the message type.

type Migration

type Migration struct {
	RuleMode schemaregistry.RuleMode
	Source   *schemaregistry.SchemaMetadata
	Target   *schemaregistry.SchemaMetadata
}

Migration represents a migration

type NoneAction

type NoneAction struct {
}

NoneAction represents a no-op action

func (NoneAction) Close

func (a NoneAction) Close() error

Close closes the action

func (NoneAction) Configure

func (a NoneAction) Configure(clientConfig *schemaregistry.Config, config map[string]string) error

Configure configures the action

func (NoneAction) Run

func (a NoneAction) Run(ctx RuleContext, msg interface{}, err error) error

Run runs the action

func (NoneAction) Type

func (a NoneAction) Type() string

Type returns the type

type RuleAction

type RuleAction interface {
	RuleBase
	Run(ctx RuleContext, msg interface{}, err error) error
}

RuleAction represents a rule action

func GetRuleAction

func GetRuleAction(name string) RuleAction

GetRuleAction fetches a rule action by a given name.

func GetRuleActions

func GetRuleActions() []RuleAction

GetRuleActions fetches all rule actions

type RuleBase

type RuleBase interface {
	Configure(clientConfig *schemaregistry.Config, config map[string]string) error
	Type() string
	Close() error
}

RuleBase represents a rule base

type RuleConditionErr

type RuleConditionErr struct {
	Rule *schemaregistry.Rule
	Err  error
}

RuleConditionErr represents a rule condition error

func (RuleConditionErr) Error

func (re RuleConditionErr) Error() string

Error returns the error message

type RuleContext

type RuleContext struct {
	Source           *schemaregistry.SchemaInfo
	Target           *schemaregistry.SchemaInfo
	Subject          string
	Topic            string
	IsKey            bool
	RuleMode         schemaregistry.RuleMode
	Rule             *schemaregistry.Rule
	Index            int
	Rules            []schemaregistry.Rule
	FieldTransformer FieldTransformer
	// contains filtered or unexported fields
}

RuleContext represents a rule context

func (*RuleContext) CurrentField

func (r *RuleContext) CurrentField() *FieldContext

CurrentField returns the current field context

func (*RuleContext) EnterField

func (r *RuleContext) EnterField(containingMessage interface{}, fullName string,
	name string, fieldType FieldType, tags []string) (FieldContext, bool)

EnterField enters a field context

func (*RuleContext) GetParameter

func (r *RuleContext) GetParameter(name string) *string

GetParameter returns a parameter by name

func (*RuleContext) GetTags

func (r *RuleContext) GetTags(fullName string) map[string]bool

GetTags returns tags for a full name

func (*RuleContext) LeaveField

func (r *RuleContext) LeaveField()

LeaveField leaves a field context

type RuleExecutor

type RuleExecutor interface {
	RuleBase
	Transform(ctx RuleContext, msg interface{}) (interface{}, error)
}

RuleExecutor represents a rule executor

func GetRuleExecutor

func GetRuleExecutor(name string) RuleExecutor

GetRuleExecutor fetches a rule executor by a given name.

func GetRuleExecutors

func GetRuleExecutors() []RuleExecutor

GetRuleExecutors fetches all rule executors

type Serde

type Serde struct {
	Client              schemaregistry.Client
	SerdeType           Type
	SubjectNameStrategy SubjectNameStrategyFunc
	MessageFactory      MessageFactory
	FieldTransformer    FieldTransformer
}

Serde is a common instance for both the serializers and deserializers

func (*Serde) Close

func (s *Serde) Close() error

Close closes the Serde

func (*Serde) ExecuteMigrations

func (s *Serde) ExecuteMigrations(migrations []Migration, subject string, topic string, msg interface{}) (interface{}, error)

ExecuteMigrations executes the given migrations

func (*Serde) ExecuteRules

func (s *Serde) ExecuteRules(subject string, topic string, ruleMode schemaregistry.RuleMode,
	source *schemaregistry.SchemaInfo, target *schemaregistry.SchemaInfo, msg interface{}) (interface{}, error)

ExecuteRules executes the given rules

func (*Serde) GetMigrations

func (s *Serde) GetMigrations(subject string, topic string, sourceInfo *schemaregistry.SchemaInfo,
	target *schemaregistry.SchemaMetadata, msg interface{}) ([]Migration, error)

GetMigrations returns the migration rules for the given subject

type Serializer

type Serializer interface {
	ConfigureSerializer(client schemaregistry.Client, serdeType Type,
		conf *SerializerConfig) error
	// Serialize will serialize the given message, which should be a pointer.
	// For example, in Protobuf, messages are always a pointer to a struct and never just a struct.
	Serialize(topic string, msg interface{}) ([]byte, error)
	Close() error
}

Serializer represents a serializer

type SerializerConfig

type SerializerConfig struct {
	// AutoRegisterSchemas determines whether to automatically register schemas during serialization
	AutoRegisterSchemas bool
	// UseSchemaID specifies a schema ID to use during serialization
	UseSchemaID int
	// UseLatestVersion specifies whether to use the latest schema version during serialization
	UseLatestVersion bool
	// UseLatestWithMetadata specifies whether to use the latest schema with metadata during serialization
	UseLatestWithMetadata map[string]string
	// NormalizeSchemas determines whether to normalize schemas during serialization
	NormalizeSchemas bool
	// RuleConfig specifies configuration options to the rules
	RuleConfig map[string]string
}

SerializerConfig is used to pass multiple configuration options to the serializers.

func NewSerializerConfig

func NewSerializerConfig() *SerializerConfig

NewSerializerConfig returns a new configuration instance with sane defaults.

type SubjectNameStrategyFunc

type SubjectNameStrategyFunc func(topic string, serdeType Type, schema schemaregistry.SchemaInfo) (string, error)

SubjectNameStrategyFunc determines the subject for the given parameters

type Type

type Type = int

Type represents the type of Serde

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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