Documentation ¶
Overview ¶
Package protoavro provides functions for converting between Protocol Buffers and Avro.
Index ¶
- func InferSchema(desc protoreflect.MessageDescriptor) (avro.Schema, error)
- type Marshaler
- type SchemaOptions
- func (o SchemaOptions) Encode(message proto.Message) (interface{}, error)
- func (o SchemaOptions) InferSchema(desc protoreflect.MessageDescriptor) (avro.Schema, error)
- func (o SchemaOptions) NewMarshaler(descriptor protoreflect.MessageDescriptor, writer io.Writer) (*Marshaler, error)
- func (o SchemaOptions) NewUnmarshaler(reader io.Reader) (*Unmarshaler, error)
- type Unmarshaler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InferSchema ¶
func InferSchema(desc protoreflect.MessageDescriptor) (avro.Schema, error)
InferSchema returns the Avro schema, with default SchemaOptions, for the protobuf message descriptor.
Example ¶
msg := &library.Book{} schema, err := protoavro.SchemaOptions{}.InferSchema(msg.ProtoReflect().Descriptor()) if err != nil { panic(err) } expected := avro.Nullable(avro.Record{ Type: avro.RecordType, Name: "Book", Namespace: "google.example.library.v1", Fields: []avro.Field{ {Name: "name", Type: avro.Nullable(avro.String())}, {Name: "author", Type: avro.Nullable(avro.String())}, {Name: "title", Type: avro.Nullable(avro.String())}, {Name: "read", Type: avro.Nullable(avro.Boolean())}, }, }) fmt.Println(cmp.Equal(expected, schema))
Output: true
Types ¶
type Marshaler ¶
type Marshaler struct {
// contains filtered or unexported fields
}
Marshaler encodes and writes Avro binary encoded messages.
Example ¶
var msg library.Book var b bytes.Buffer marshaller, err := protoavro.NewMarshaler(msg.ProtoReflect().Descriptor(), &b) if err != nil { panic(err) } if err := marshaller.Marshal( &library.Book{ Name: "shelves/1/books/1", Title: "Harry Potter", Author: "J. K. Rowling", }, ); err != nil { panic(err) }
Output:
func NewMarshaler ¶
func NewMarshaler(descriptor protoreflect.MessageDescriptor, writer io.Writer) (*Marshaler, error)
NewMarshaler returns a new marshaler, with default SchemaOptions, that writes protobuf messages to writer in Avro binary format.
type SchemaOptions ¶ added in v0.6.0
type SchemaOptions struct {
OmitRootElement bool
}
SchemaOptions contains configuration options for Avro schema inference. OmitRootElement is used to determine whether the root element of a message should be omitted, when writing to Avro.
func (SchemaOptions) Encode ¶ added in v0.6.0
func (o SchemaOptions) Encode(message proto.Message) (interface{}, error)
Encode encodes the message.
func (SchemaOptions) InferSchema ¶ added in v0.6.0
func (o SchemaOptions) InferSchema(desc protoreflect.MessageDescriptor) (avro.Schema, error)
InferSchema returns the Avro schema for the protobuf message descriptor.
func (SchemaOptions) NewMarshaler ¶ added in v0.6.0
func (o SchemaOptions) NewMarshaler(descriptor protoreflect.MessageDescriptor, writer io.Writer) (*Marshaler, error)
NewMarshaler returns a new marshaler that writes protobuf messages to writer in Avro binary format.
func (SchemaOptions) NewUnmarshaler ¶ added in v0.6.0
func (o SchemaOptions) NewUnmarshaler(reader io.Reader) (*Unmarshaler, error)
NewUnmarshaler returns a new unmarshaler that reads protobuf messages from reader in Avro binary format.
type Unmarshaler ¶
type Unmarshaler struct {
// contains filtered or unexported fields
}
Unmarshaler reads and decodes Avro binary encoded messages.
func NewUnmarshaler ¶
func NewUnmarshaler(reader io.Reader) (*Unmarshaler, error)
NewUnmarshaler returns a new unmarshaler that reads protobuf messages from reader in Avro binary format.
func (*Unmarshaler) Scan ¶
func (m *Unmarshaler) Scan() bool
Scan returns true when there is at least one more message to be read. Scan should be called prior to calling Unmarshal.