schema

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// mapping proto type to avro primitive type
	ProtoType2AvroType = map[descriptor.FieldDescriptorProto_Type]string{
		descriptor.FieldDescriptorProto_TYPE_DOUBLE:  "double",
		descriptor.FieldDescriptorProto_TYPE_FLOAT:   "float",
		descriptor.FieldDescriptorProto_TYPE_INT64:   "long",
		descriptor.FieldDescriptorProto_TYPE_UINT64:  "long",
		descriptor.FieldDescriptorProto_TYPE_INT32:   "int",
		descriptor.FieldDescriptorProto_TYPE_FIXED64: "long",
		descriptor.FieldDescriptorProto_TYPE_FIXED32: "int",
		descriptor.FieldDescriptorProto_TYPE_BOOL:    "boolean",
		descriptor.FieldDescriptorProto_TYPE_STRING:  "string",

		descriptor.FieldDescriptorProto_TYPE_BYTES:  "bytes",
		descriptor.FieldDescriptorProto_TYPE_UINT32: "int",

		descriptor.FieldDescriptorProto_TYPE_SFIXED32: "int",
		descriptor.FieldDescriptorProto_TYPE_SFIXED64: "long",
		descriptor.FieldDescriptorProto_TYPE_SINT32:   "int",
		descriptor.FieldDescriptorProto_TYPE_SINT64:   "long",
	}

	// mapping proto type to avro zero-value to use it as default
	ProtoType2AvroDefault = map[descriptor.FieldDescriptorProto_Type]interface{}{
		descriptor.FieldDescriptorProto_TYPE_DOUBLE:  0,
		descriptor.FieldDescriptorProto_TYPE_FLOAT:   0,
		descriptor.FieldDescriptorProto_TYPE_INT64:   0,
		descriptor.FieldDescriptorProto_TYPE_UINT64:  0,
		descriptor.FieldDescriptorProto_TYPE_INT32:   0,
		descriptor.FieldDescriptorProto_TYPE_FIXED64: 0,
		descriptor.FieldDescriptorProto_TYPE_FIXED32: 0,
		descriptor.FieldDescriptorProto_TYPE_BOOL:    false,
		descriptor.FieldDescriptorProto_TYPE_STRING:  "",

		descriptor.FieldDescriptorProto_TYPE_MESSAGE: nil,
		descriptor.FieldDescriptorProto_TYPE_BYTES:   []byte{},
		descriptor.FieldDescriptorProto_TYPE_UINT32:  0,

		descriptor.FieldDescriptorProto_TYPE_SFIXED32: 0,
		descriptor.FieldDescriptorProto_TYPE_SFIXED64: 0,
		descriptor.FieldDescriptorProto_TYPE_SINT32:   0,
		descriptor.FieldDescriptorProto_TYPE_SINT64:   0,
	}
)
View Source
var (
	ErrUnknownProtoType = fmt.Errorf("The protobuf type is unknown")
)

Functions

func GetNamespace

func GetNamespace(fullName string) string

GetNamespace gets 'namespace' field in Avro from proto message name.

func GetNestedRecordSchemaFromDescriptor

func GetNestedRecordSchemaFromDescriptor(fd *genDescriptor.FileDescriptorProto, md *genDescriptor.DescriptorProto, ns string) ([]interface{}, error)

func GetRecordSchemaFieldFromDescriptor

func GetRecordSchemaFieldFromDescriptor(d *genDescriptor.FieldDescriptorProto, fd *genDescriptor.FileDescriptorProto, tm typeMap) (map[string]interface{}, error)

func GetRecordSchemaFromDescriptor

func GetRecordSchemaFromDescriptor(fd *genDescriptor.FileDescriptorProto, md *genDescriptor.DescriptorProto, ns string) (map[string]interface{}, error)

func GetRecordSchemaFromMessage

func GetRecordSchemaFromMessage(msg descriptor.Message) (map[string]interface{}, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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