serde

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 8 Imported by: 9

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
)

Variables

This section is empty.

Functions

func Expect

func Expect(actual, expected interface{}) error

Expect compares the actual and expected values

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 BaseDeserializer

type BaseDeserializer struct {
	Serde
	Conf           *DeserializerConfig
	MessageFactory MessageFactory
}

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) 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()
}

Deserializer represents a deserializer

type DeserializerConfig

type DeserializerConfig struct {
}

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 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

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. For Protobuf, the name will be the name of the message type.

type Serde

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

Serde is a common instance for both the serializers and deserializers

func (*Serde) Close

func (s *Serde) Close()

Close closes the Serde

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()
}

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
	// NormalizeSchemas determines whether to normalize schemas during serialization
	NormalizeSchemas bool
}

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