avroutil

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithMaxByteSliceSize added in v0.3.6

func WithMaxByteSliceSize(maxSize int) option

WithMaxByteSliceSize is the maximum size of `bytes` or `string` types the Reader will create, defaulting to 10MiB. If this size is exceeded, the Reader returns an error. This can be disabled by setting a negative number.

Types

type Decoder

type Decoder interface {
	// Decode decodes @data, in the wire format, into @output.
	Decode(ctx context.Context, data []byte, output interface{}) error
}

Decoder is able to transform avro's wire format data into golang's concrete types

func NewDecoder

func NewDecoder(schemaRepository schemaregistry.Repository, options ...option) Decoder

NewDecoder returns a concrete implementation of Decoder, that fetches schemas in schema registry

type Encoder

type Encoder interface {
	// Encode encodes @input in the wire format
	Encode(input interface{}) ([]byte, error)
}

Encoder is able to transform golang's concrete types into avro's wire format

func NewEncoder

func NewEncoder(
	ctx context.Context,
	schemaRepository schemaregistry.Repository,
	subject schemaregistry.Subject,
	writerSchemaStr string,
	options ...option,
) (Encoder, error)

NewEncoder returns a concrete implementation of Decoder, that fetches schemas in schema registry Parameters:

  • @schemaRepository: repository for avro schemas.
  • @writerSchemaStr: avro schema, in the AVSC format, used to marshall the objects. This schema must be previously registered in the schema registry exactly as provided.

type MockDecoder

type MockDecoder struct {
	mock.Mock
}

MockDecoder is a special implementation of Decoder, useful for unit testing

func (*MockDecoder) AddBinding

func (i *MockDecoder) AddBinding(data []byte, output interface{}, err error) *mock.Call

AddBinding mocks the decoding result of @data to the @output struct

func (*MockDecoder) AddJSONBinding

func (i *MockDecoder) AddJSONBinding(data []byte, output string, err error) *mock.Call

AddJSONBinding mocks the decoding of @data with the JSON-encoded data in @output. Use this function when the output structure is hard to define in unit tests, ex: anonymous structs with lots of pointers.

func (*MockDecoder) Decode

func (i *MockDecoder) Decode(ctx context.Context, data []byte, output interface{}) error

Decode decodes @data, in the wire format, into @output.

type WireFormatEncoder

type WireFormatEncoder interface {
	BinaryToWireFormat(avroInput []byte) ([]byte, error)
}

WireFormatEncoder uses the Schema ID provided in the constructor to encodes Avro Messages of the same type into its Wire Format form. The `WireFormatEncoder` is used undercover by `Encoder` to deal with the Wire Format transformation step.

func NewWireFormatEncoder

func NewWireFormatEncoder(
	ctx context.Context,
	schemaRepository schemaregistry.Repository,
	subject schemaregistry.Subject,
	writerSchemaStr string,
) (WireFormatEncoder, error)

NewWireFormatEncoder returns a concrete implementation of WireFormatEncoder, that fetches schemas in schema registry Parameters:

  • @schemaRepository: repository for avro schemas.
  • @writerSchemaStr: avro schema, in the avsc format, used to marshall the objects. This schema must be previously registered in the schema registry exactly as provided.

Directories

Path Synopsis
This is a simple example that shows how to use avroutil package.
This is a simple example that shows how to use avroutil package.

Jump to

Keyboard shortcuts

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