schema

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidProtoIsNil is returned when trying to convert a schema object to a
	// proto schema, and the proto is nil.
	ErrInvalidProtoIsNil = errors.New("invalid proto: nil")

	// ErrUnsupportedType is returned when an unsupported type is encountered.
	ErrUnsupportedType = errors.New("unsupported type")
)
View Source
var KnownSerdeFactories = map[Type]SerdeFactory{
	TypeAvro: {
		Parse:        func(s []byte) (Serde, error) { return avro.Parse(s) },
		SerdeForType: func(v any) (Serde, error) { return avro.SerdeForType(v) },
	},
}

Functions

func AttachKeySchemaToRecord

func AttachKeySchemaToRecord(r opencdc.Record, s Schema)

func AttachPayloadSchemaToRecord

func AttachPayloadSchemaToRecord(r opencdc.Record, s Schema)

Types

type Schema

type Schema struct {
	Subject string
	Version int
	ID      int
	Type    Type
	Bytes   []byte
}

func (Schema) Fingerprint

func (s Schema) Fingerprint() uint64

Fingerprint returns a unique 64 bit identifier for the schema.

func (*Schema) FromProto

func (s *Schema) FromProto(proto *schemav1.Schema) error

FromProto takes data from the supplied proto object and populates the receiver. If the proto object is nil, the receiver is set to its zero value. If the function returns an error, the receiver could be partially populated.

func (Schema) Marshal

func (s Schema) Marshal(v any) ([]byte, error)

Marshal returns the encoded representation of v.

func (Schema) Serde

func (s Schema) Serde() (Serde, error)

Serde returns the serde for the schema.

func (*Schema) ToProto

func (s *Schema) ToProto(proto *schemav1.Schema) error

ToProto takes data from the receiver and populates the supplied proto object. If the function returns an error, the proto object could be partially populated.

func (Schema) Unmarshal

func (s Schema) Unmarshal(b []byte, v any) error

Unmarshal parses encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an error.

type Serde

type Serde interface {
	// Marshal returns the encoded representation of v.
	Marshal(v any) ([]byte, error)
	// Unmarshal parses encoded data and stores the result in the value pointed
	// to by v. If v is nil or not a pointer, Unmarshal returns an error.
	Unmarshal(b []byte, v any) error
	// String returns the textual representation of the schema used by this serde.
	String() string
}

Serde represents a serializer/deserializer.

type SerdeFactory

type SerdeFactory struct {
	// Parse takes the textual representation of the schema and parses it into
	// a Schema.
	Parse func([]byte) (Serde, error)
	// SerdeForType returns a Schema that matches the structure of v.
	SerdeForType func(v any) (Serde, error)
}

type Type

type Type int32
const (
	TypeAvro Type = iota + 1 // avro
)

func (Type) MarshalText

func (t Type) MarshalText() ([]byte, error)

MarshalText returns the textual representation of the schema type.

func (Type) String

func (i Type) String() string

func (*Type) UnmarshalText

func (t *Type) UnmarshalText(b []byte) error

UnmarshalText parses the textual representation of the schema type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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