schema

package
v9.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

gogen-avro's internal representation of Avro schemas

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayField

type ArrayField struct {
	// contains filtered or unexported fields
}

func NewArrayField

func NewArrayField(itemType AvroType, definition map[string]interface{}) *ArrayField

func (*ArrayField) Attribute

func (s *ArrayField) Attribute(name string) interface{}

func (*ArrayField) Children

func (s *ArrayField) Children() []AvroType

func (*ArrayField) ConstructorMethod

func (s *ArrayField) ConstructorMethod() string

func (*ArrayField) DefaultValue

func (s *ArrayField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*ArrayField) Definition

func (s *ArrayField) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*ArrayField) GoType

func (s *ArrayField) GoType() string

func (*ArrayField) IsReadableBy

func (s *ArrayField) IsReadableBy(f AvroType) bool

func (*ArrayField) ItemConstructable

func (s *ArrayField) ItemConstructable() string

func (*ArrayField) ItemType

func (s *ArrayField) ItemType() AvroType

func (*ArrayField) Name

func (s *ArrayField) Name() string

func (*ArrayField) SerializerMethod

func (s *ArrayField) SerializerMethod() string

func (*ArrayField) UnionKey

func (s *ArrayField) UnionKey() string

func (*ArrayField) WrapperType

func (s *ArrayField) WrapperType() string

type AvroType

type AvroType interface {
	Name() string
	GoType() string
	// The key to use in JSON-encoding a union with this value
	UnionKey() string

	// The name of the method which writes this field onto the wire
	SerializerMethod() string

	Children() []AvroType

	Attribute(name string) interface{}
	Definition(scope map[QualifiedName]interface{}) (interface{}, error)
	DefaultValue(lvalue string, rvalue interface{}) (string, error)

	// WrapperType is the VM type to wrap this value in, if applicable
	WrapperType() string
	IsReadableBy(f AvroType) bool
}

type BoolField

type BoolField struct {
	PrimitiveField
}

func NewBoolField

func NewBoolField(definition interface{}) *BoolField

func (*BoolField) DefaultValue

func (s *BoolField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*BoolField) IsReadableBy

func (s *BoolField) IsReadableBy(f AvroType) bool

func (*BoolField) WrapperType

func (s *BoolField) WrapperType() string

type BytesField

type BytesField struct {
	PrimitiveField
}

func NewBytesField

func NewBytesField(definition interface{}) *BytesField

func (*BytesField) DefaultValue

func (s *BytesField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*BytesField) IsReadableBy

func (s *BytesField) IsReadableBy(f AvroType) bool

func (*BytesField) WrapperType

func (s *BytesField) WrapperType() string

type Constructable

type Constructable interface {
	ConstructorMethod() string
}

type Definition

type Definition interface {
	AvroName() QualifiedName
	Aliases() []QualifiedName

	// A user-friendly name that can be built into a Go string (for unions, mostly)
	Name() string

	GoType() string

	SerializerMethod() string

	Children() []AvroType

	Attribute(name string) interface{}
	// A JSON object defining this object, for writing the schema back out
	Definition(scope map[QualifiedName]interface{}) (interface{}, error)
	DefaultValue(lvalue string, rvalue interface{}) (string, error)

	IsReadableBy(f Definition) bool
	WrapperType() string
}

type DoubleField

type DoubleField struct {
	PrimitiveField
}

func NewDoubleField

func NewDoubleField(definition interface{}) *DoubleField

func (*DoubleField) DefaultValue

func (s *DoubleField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*DoubleField) IsReadableBy

func (s *DoubleField) IsReadableBy(f AvroType) bool

func (*DoubleField) WrapperType

func (s *DoubleField) WrapperType() string

type EnumDefinition

type EnumDefinition struct {
	// contains filtered or unexported fields
}

func NewEnumDefinition

func NewEnumDefinition(name QualifiedName, aliases []QualifiedName, symbols []string, doc string, definition map[string]interface{}) *EnumDefinition

func (*EnumDefinition) Aliases

func (e *EnumDefinition) Aliases() []QualifiedName

func (*EnumDefinition) Attribute

func (s *EnumDefinition) Attribute(name string) interface{}

func (*EnumDefinition) AvroName

func (e *EnumDefinition) AvroName() QualifiedName

func (*EnumDefinition) Children

func (s *EnumDefinition) Children() []AvroType

func (*EnumDefinition) DefaultValue

func (s *EnumDefinition) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*EnumDefinition) Definition

func (s *EnumDefinition) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*EnumDefinition) Doc

func (e *EnumDefinition) Doc() string

func (*EnumDefinition) FromStringMethod

func (e *EnumDefinition) FromStringMethod() string

func (*EnumDefinition) GoType

func (e *EnumDefinition) GoType() string

func (*EnumDefinition) IsReadableBy

func (s *EnumDefinition) IsReadableBy(d Definition) bool

func (*EnumDefinition) Name

func (e *EnumDefinition) Name() string

func (*EnumDefinition) SerializerMethod

func (e *EnumDefinition) SerializerMethod() string

func (*EnumDefinition) SymbolName

func (e *EnumDefinition) SymbolName(symbol string) string

func (*EnumDefinition) Symbols

func (e *EnumDefinition) Symbols() []string

func (*EnumDefinition) WrapperType

func (s *EnumDefinition) WrapperType() string

type Field

type Field struct {
	// contains filtered or unexported fields
}

func NewField

func NewField(avroName string, avroType AvroType, defValue interface{}, hasDef bool, aliases []string, doc string, definition map[string]interface{}, index int, fieldTags string) *Field

func (*Field) Aliases

func (f *Field) Aliases() []string

func (*Field) Default

func (f *Field) Default() interface{}

func (*Field) Definition

func (f *Field) Definition(scope map[QualifiedName]interface{}) (map[string]interface{}, error)

func (*Field) Doc

func (f *Field) Doc() string

func (*Field) GoName

func (f *Field) GoName() string

func (*Field) HasDefault

func (f *Field) HasDefault() bool

func (*Field) Index

func (f *Field) Index() int

func (*Field) Name

func (f *Field) Name() string

func (*Field) NameMatchesAliases

func (f *Field) NameMatchesAliases(writerName string) bool

NameMatchesAliases checks whether this field, in the reader schema, has a name or alias equal to the name in the writer schema

func (*Field) Tags

func (f *Field) Tags() string

Tags returns a field go struct tags if defined.

func (*Field) Type

func (f *Field) Type() AvroType

type FileRoot

type FileRoot struct {
	Type AvroType
}

FileRoot represents the Avro type at the root of a given schema file, and implements Definition. This is necessary for files which contain a union, array, map, etc. at the top level since these types don't otherwise have a Definition which would result in code being generated.

func (*FileRoot) Aliases

func (f *FileRoot) Aliases() []QualifiedName

func (*FileRoot) Attribute

func (f *FileRoot) Attribute(name string) interface{}

func (*FileRoot) AvroName

func (f *FileRoot) AvroName() QualifiedName

func (*FileRoot) Children

func (f *FileRoot) Children() []AvroType

func (*FileRoot) DefaultValue

func (f *FileRoot) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*FileRoot) Definition

func (f *FileRoot) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*FileRoot) GoType

func (f *FileRoot) GoType() string

func (*FileRoot) IsReadableBy

func (f *FileRoot) IsReadableBy(_ Definition) bool

func (*FileRoot) Name

func (f *FileRoot) Name() string

func (*FileRoot) SerializerMethod

func (f *FileRoot) SerializerMethod() string

func (*FileRoot) WrapperType

func (f *FileRoot) WrapperType() string

type FixedDefinition

type FixedDefinition struct {
	// contains filtered or unexported fields
}

func NewFixedDefinition

func NewFixedDefinition(name QualifiedName, aliases []QualifiedName, sizeBytes int, definition map[string]interface{}) *FixedDefinition

func (*FixedDefinition) Aliases

func (s *FixedDefinition) Aliases() []QualifiedName

func (*FixedDefinition) Attribute

func (s *FixedDefinition) Attribute(name string) interface{}

func (*FixedDefinition) AvroName

func (s *FixedDefinition) AvroName() QualifiedName

func (*FixedDefinition) Children

func (s *FixedDefinition) Children() []AvroType

func (*FixedDefinition) DefaultValue

func (s *FixedDefinition) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*FixedDefinition) Definition

func (s *FixedDefinition) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*FixedDefinition) GoType

func (s *FixedDefinition) GoType() string

func (*FixedDefinition) IsReadableBy

func (s *FixedDefinition) IsReadableBy(d Definition) bool

func (*FixedDefinition) Name

func (s *FixedDefinition) Name() string

func (*FixedDefinition) SerializerMethod

func (s *FixedDefinition) SerializerMethod() string

func (*FixedDefinition) SizeBytes

func (s *FixedDefinition) SizeBytes() int

func (*FixedDefinition) WrapperType

func (s *FixedDefinition) WrapperType() string

type FloatField

type FloatField struct {
	PrimitiveField
}

func NewFloatField

func NewFloatField(definition interface{}) *FloatField

func (*FloatField) DefaultValue

func (s *FloatField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*FloatField) IsReadableBy

func (s *FloatField) IsReadableBy(f AvroType) bool

func (*FloatField) WrapperType

func (s *FloatField) WrapperType() string

type IntField

type IntField struct {
	PrimitiveField
}

func NewIntField

func NewIntField(definition interface{}) *IntField

func (*IntField) DefaultValue

func (s *IntField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*IntField) IsReadableBy

func (s *IntField) IsReadableBy(f AvroType) bool

func (*IntField) WrapperType

func (s *IntField) WrapperType() string

type LongField

type LongField struct {
	PrimitiveField
}

func NewLongField

func NewLongField(definition interface{}) *LongField

func (*LongField) DefaultValue

func (s *LongField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*LongField) IsReadableBy

func (s *LongField) IsReadableBy(f AvroType) bool

func (*LongField) WrapperType

func (s *LongField) WrapperType() string

type MapField

type MapField struct {
	// contains filtered or unexported fields
}

func NewMapField

func NewMapField(itemType AvroType, definition map[string]interface{}) *MapField

func (*MapField) Attribute

func (s *MapField) Attribute(name string) interface{}

func (*MapField) Children

func (s *MapField) Children() []AvroType

func (*MapField) ConstructorMethod

func (s *MapField) ConstructorMethod() string

func (*MapField) DefaultValue

func (s *MapField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*MapField) Definition

func (s *MapField) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*MapField) GoType

func (s *MapField) GoType() string

func (*MapField) IsReadableBy

func (s *MapField) IsReadableBy(f AvroType) bool

func (*MapField) ItemConstructable

func (s *MapField) ItemConstructable() string

func (*MapField) ItemType

func (s *MapField) ItemType() AvroType

func (*MapField) Name

func (s *MapField) Name() string

func (*MapField) SerializerMethod

func (s *MapField) SerializerMethod() string

func (*MapField) UnionKey

func (s *MapField) UnionKey() string

func (*MapField) WrapperType

func (s *MapField) WrapperType() string

type Node

type Node interface {
	Name() string
	Children() []AvroType
}

type NullField

type NullField struct {
	PrimitiveField
}

func NewNullField

func NewNullField(definition interface{}) *NullField

func (*NullField) DefaultValue

func (s *NullField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*NullField) IsReadableBy

func (s *NullField) IsReadableBy(f AvroType) bool

func (*NullField) WrapperType

func (s *NullField) WrapperType() string

type PrimitiveField

type PrimitiveField struct {
	// contains filtered or unexported fields
}

Common methods for all primitive types

func (*PrimitiveField) Attribute

func (s *PrimitiveField) Attribute(name string) interface{}

func (*PrimitiveField) Children

func (s *PrimitiveField) Children() []AvroType

func (*PrimitiveField) Definition

func (s *PrimitiveField) Definition(_ map[QualifiedName]interface{}) (interface{}, error)

func (*PrimitiveField) GoType

func (s *PrimitiveField) GoType() string

func (*PrimitiveField) Name

func (s *PrimitiveField) Name() string

func (*PrimitiveField) SerializerMethod

func (s *PrimitiveField) SerializerMethod() string

func (*PrimitiveField) UnionKey

func (s *PrimitiveField) UnionKey() string

type QualifiedName

type QualifiedName struct {
	Namespace string
	Name      string
}

QualifiedName represents an Avro qualified name, which includes an optional namespace and the type name.

func (QualifiedName) String

func (q QualifiedName) String() string

type RecordDefinition

type RecordDefinition struct {
	// contains filtered or unexported fields
}

func NewRecordDefinition

func NewRecordDefinition(name QualifiedName, aliases []QualifiedName, fields []*Field, doc string, metadata map[string]interface{}) *RecordDefinition

func (*RecordDefinition) Aliases

func (r *RecordDefinition) Aliases() []QualifiedName

func (*RecordDefinition) Attribute

func (s *RecordDefinition) Attribute(name string) interface{}

func (*RecordDefinition) AvroName

func (r *RecordDefinition) AvroName() QualifiedName

func (*RecordDefinition) Children

func (s *RecordDefinition) Children() []AvroType

func (*RecordDefinition) ConstructableForField

func (r *RecordDefinition) ConstructableForField(f *Field) string

func (*RecordDefinition) ConstructorMethod

func (r *RecordDefinition) ConstructorMethod() string

func (*RecordDefinition) DefaultForField

func (r *RecordDefinition) DefaultForField(f *Field) (string, error)

func (*RecordDefinition) DefaultValue

func (r *RecordDefinition) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*RecordDefinition) Definition

func (r *RecordDefinition) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*RecordDefinition) Doc

func (s *RecordDefinition) Doc() string

func (*RecordDefinition) FieldByName

func (r *RecordDefinition) FieldByName(field string) *Field

FieldByName finds a field in the reader schema whose name or aliases match a name in the writer schema.

func (*RecordDefinition) Fields

func (r *RecordDefinition) Fields() []*Field

func (*RecordDefinition) GetReference

func (s *RecordDefinition) GetReference() bool

func (*RecordDefinition) GoType

func (r *RecordDefinition) GoType() string

func (*RecordDefinition) IsReadableBy

func (s *RecordDefinition) IsReadableBy(d Definition) bool

func (*RecordDefinition) Name

func (r *RecordDefinition) Name() string

func (*RecordDefinition) NewWriterMethod

func (r *RecordDefinition) NewWriterMethod() string

func (*RecordDefinition) RecordReaderTypeName

func (r *RecordDefinition) RecordReaderTypeName() string

func (*RecordDefinition) Schema

func (s *RecordDefinition) Schema() (string, error)

func (*RecordDefinition) SerializerMethod

func (r *RecordDefinition) SerializerMethod() string

func (*RecordDefinition) WrapperType

func (s *RecordDefinition) WrapperType() string

type Reference

type Reference struct {
	TypeName QualifiedName
	Def      Definition
}

Reference to a user-defined type (fixed, enum, record). Just a wrapper with a name around a Definition.

func NewReference

func NewReference(typeName QualifiedName) *Reference

func (*Reference) Attribute

func (s *Reference) Attribute(name string) interface{}

func (*Reference) Children

func (s *Reference) Children() []AvroType

func (*Reference) DefaultValue

func (s *Reference) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*Reference) Definition

func (s *Reference) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*Reference) GoType

func (s *Reference) GoType() string

func (*Reference) IsReadableBy

func (s *Reference) IsReadableBy(f AvroType) bool

func (*Reference) Name

func (s *Reference) Name() string

func (*Reference) SerializerMethod

func (s *Reference) SerializerMethod() string

func (*Reference) UnionKey

func (s *Reference) UnionKey() string

func (*Reference) WrapperType

func (s *Reference) WrapperType() string

type StringField

type StringField struct {
	PrimitiveField
}

func NewStringField

func NewStringField(definition interface{}) *StringField

func (*StringField) DefaultValue

func (s *StringField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*StringField) IsReadableBy

func (s *StringField) IsReadableBy(f AvroType) bool

func (*StringField) WrapperType

func (s *StringField) WrapperType() string

type UnionField

type UnionField struct {
	// contains filtered or unexported fields
}

func NewUnionField

func NewUnionField(name string, itemType []AvroType, definition []interface{}) *UnionField

func (*UnionField) Attribute

func (s *UnionField) Attribute(name string) interface{}

func (*UnionField) AvroTypes

func (s *UnionField) AvroTypes() []AvroType

func (*UnionField) Children

func (s *UnionField) Children() []AvroType

func (*UnionField) ConstructorMethod

func (s *UnionField) ConstructorMethod() string

func (*UnionField) DefaultValue

func (s *UnionField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*UnionField) Definition

func (s *UnionField) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*UnionField) Equals

func (s *UnionField) Equals(reader *UnionField) bool

func (*UnionField) GetReference

func (s *UnionField) GetReference() bool

func (*UnionField) GoType

func (s *UnionField) GoType() string

func (*UnionField) IsReadableBy

func (s *UnionField) IsReadableBy(f AvroType) bool

func (*UnionField) ItemConstructor

func (s *UnionField) ItemConstructor(f AvroType) string

func (*UnionField) ItemName

func (s *UnionField) ItemName(item AvroType) string

func (*UnionField) ItemTypes

func (s *UnionField) ItemTypes() []AvroType

func (*UnionField) Name

func (s *UnionField) Name() string

func (*UnionField) NullIndex

func (s *UnionField) NullIndex() int

func (*UnionField) Schema

func (s *UnionField) Schema() (string, error)

func (*UnionField) SerializerMethod

func (s *UnionField) SerializerMethod() string

func (*UnionField) UnionEnumType

func (s *UnionField) UnionEnumType() string

func (*UnionField) UnionKey

func (s *UnionField) UnionKey() string

func (*UnionField) WrapperType

func (s *UnionField) WrapperType() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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