Documentation ¶
Index ¶
- Variables
- func Marshal(schema Schema, v any) ([]byte, error)
- func Register(name string, obj any)
- func RegisterSchemaByValue(v any)
- func Unmarshal(schema Schema, data []byte, v any) error
- type API
- type ArraySchema
- func (s *ArraySchema) Fingerprint() [32]byte
- func (s *ArraySchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
- func (s *ArraySchema) Items() Schema
- func (s *ArraySchema) MarshalJSON() ([]byte, error)
- func (p ArraySchema) Prop(name string) any
- func (s *ArraySchema) String() string
- func (s *ArraySchema) Type() Type
- type Config
- type DecimalLogicalSchema
- type Decoder
- type Encoder
- type EnumSchema
- func (n EnumSchema) Aliases() []string
- func (s *EnumSchema) Default() string
- func (s *EnumSchema) Doc() string
- func (s *EnumSchema) Fingerprint() [32]byte
- func (s *EnumSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
- func (n EnumSchema) FullName() string
- func (s *EnumSchema) MarshalJSON() ([]byte, error)
- func (n EnumSchema) Name() string
- func (n EnumSchema) Namespace() string
- func (p EnumSchema) Prop(name string) any
- func (s *EnumSchema) String() string
- func (s *EnumSchema) Symbols() []string
- func (s *EnumSchema) Type() Type
- type Field
- func (f *Field) Aliases() []string
- func (f *Field) Default() any
- func (f *Field) Doc() string
- func (f *Field) HasDefault() bool
- func (f *Field) MarshalJSON() ([]byte, error)
- func (f *Field) Name() string
- func (f *Field) Order() Order
- func (p Field) Prop(name string) any
- func (f *Field) String() string
- func (f *Field) Type() Schema
- type FingerprintType
- type FixedSchema
- func (n FixedSchema) Aliases() []string
- func (s *FixedSchema) Fingerprint() [32]byte
- func (s *FixedSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
- func (n FixedSchema) FullName() string
- func (s *FixedSchema) Logical() LogicalSchema
- func (s *FixedSchema) MarshalJSON() ([]byte, error)
- func (n FixedSchema) Name() string
- func (n FixedSchema) Namespace() string
- func (p FixedSchema) Prop(name string) any
- func (s *FixedSchema) Size() int
- func (s *FixedSchema) String() string
- func (s *FixedSchema) Type() Type
- type LogicalDuration
- type LogicalSchema
- type LogicalType
- type LogicalTypeSchema
- type MapSchema
- func (s *MapSchema) Fingerprint() [32]byte
- func (s *MapSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
- func (s *MapSchema) MarshalJSON() ([]byte, error)
- func (p MapSchema) Prop(name string) any
- func (s *MapSchema) String() string
- func (s *MapSchema) Type() Type
- func (s *MapSchema) Values() Schema
- type Marshaler
- type Message
- type NamedSchema
- type NullSchema
- type Order
- type PrimitiveLogicalSchema
- type PrimitiveSchema
- func (s *PrimitiveSchema) Fingerprint() [32]byte
- func (s *PrimitiveSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
- func (s *PrimitiveSchema) Logical() LogicalSchema
- func (s *PrimitiveSchema) MarshalJSON() ([]byte, error)
- func (p PrimitiveSchema) Prop(name string) any
- func (s *PrimitiveSchema) String() string
- func (s *PrimitiveSchema) Type() Type
- type PropertySchema
- type Protocol
- func (n Protocol) Aliases() []string
- func (p *Protocol) Doc() string
- func (n Protocol) FullName() string
- func (p *Protocol) Hash() string
- func (p *Protocol) Message(name string) *Message
- func (n Protocol) Name() string
- func (n Protocol) Namespace() string
- func (p Protocol) Prop(name string) any
- func (p *Protocol) String() string
- func (p *Protocol) Types() []NamedSchema
- type ProtocolOption
- type Reader
- func (r *Reader) Read(b []byte)
- func (r *Reader) ReadArrayCB(fn func(*Reader) bool)
- func (r *Reader) ReadBlockHeader() (int64, int64)
- func (r *Reader) ReadBool() bool
- func (r *Reader) ReadBytes() []byte
- func (r *Reader) ReadDouble() float64
- func (r *Reader) ReadFloat() float32
- func (r *Reader) ReadInt() int32
- func (r *Reader) ReadLong() int64
- func (r *Reader) ReadMapCB(fn func(*Reader, string) bool)
- func (r *Reader) ReadNext(schema Schema) any
- func (r *Reader) ReadString() string
- func (r *Reader) ReadVal(schema Schema, obj any)
- func (r *Reader) ReportError(operation, msg string)
- func (r *Reader) Reset(b []byte) *Reader
- func (r *Reader) SkipBool()
- func (r *Reader) SkipBytes()
- func (r *Reader) SkipDouble()
- func (r *Reader) SkipFloat()
- func (r *Reader) SkipInt()
- func (r *Reader) SkipLong()
- func (r *Reader) SkipNBytes(n int)
- func (r *Reader) SkipString()
- type ReaderFunc
- type RecordSchema
- func (n RecordSchema) Aliases() []string
- func (s *RecordSchema) Doc() string
- func (s *RecordSchema) Fields() []*Field
- func (s *RecordSchema) Fingerprint() [32]byte
- func (s *RecordSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
- func (n RecordSchema) FullName() string
- func (s *RecordSchema) IsError() bool
- func (s *RecordSchema) MarshalJSON() ([]byte, error)
- func (n RecordSchema) Name() string
- func (n RecordSchema) Namespace() string
- func (p RecordSchema) Prop(name string) any
- func (s *RecordSchema) String() string
- func (s *RecordSchema) Type() Type
- type RefSchema
- type Schema
- func MustParse(schema string) Schema
- func Parse(schema string) (Schema, error)
- func ParseBytes(schema []byte) (Schema, error)
- func ParseBytesWithCache(schema []byte, namespace string, cache *SchemaCache) (Schema, error)
- func ParseFiles(paths ...string) (Schema, error)
- func ParseValue(v any) (s Schema, err error)
- func ParseWithCache(schema, namespace string, cache *SchemaCache) (Schema, error)
- type SchemaCache
- type SchemaCompatibility
- type SchemaOption
- type Schemas
- type Type
- type TypeResolver
- type UnionSchema
- func (s *UnionSchema) Fingerprint() [32]byte
- func (s *UnionSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
- func (s *UnionSchema) Indices() (null, typ int)
- func (s *UnionSchema) MarshalJSON() ([]byte, error)
- func (s *UnionSchema) Nullable() bool
- func (s *UnionSchema) String() string
- func (s *UnionSchema) Type() Type
- func (s *UnionSchema) Types() Schemas
- type Unmarshaler
- type ValDecoder
- type ValEncoder
- type Writer
- func (w *Writer) Buffer() []byte
- func (w *Writer) Buffered() int
- func (w *Writer) Flush() error
- func (w *Writer) Reset(out io.Writer)
- func (w *Writer) Write(b []byte) (int, error)
- func (w *Writer) WriteBlockCB(callback func(w *Writer) int64) int64
- func (w *Writer) WriteBlockHeader(l, s int64)
- func (w *Writer) WriteBool(b bool)
- func (w *Writer) WriteBytes(b []byte)
- func (w *Writer) WriteDouble(f float64)
- func (w *Writer) WriteFloat(f float32)
- func (w *Writer) WriteInt(i int32)
- func (w *Writer) WriteLong(i int64)
- func (w *Writer) WriteString(s string)
- func (w *Writer) WriteVal(schema Schema, val any)
- type WriterFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{}.Freeze()
DefaultConfig is the default API.
var DefaultSchemaCache = &SchemaCache{}
DefaultSchemaCache is the default cache for schemas.
var NoDefault = noDef{}
NoDefault is used when no default exists for a field.
Functions ¶
func Register ¶
Register registers names to their types for resolution. All primitive types are pre-registered.
func RegisterSchemaByValue ¶
func RegisterSchemaByValue(v any)
Types ¶
type API ¶
type API interface { // Marshal returns the Avro encoding of v. Marshal(schema Schema, v any) ([]byte, error) // Unmarshal parses the Avro 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(schema Schema, data []byte, v any) error // NewEncoder returns a new encoder that writes to w using schema. NewEncoder(schema Schema, w io.Writer) *Encoder // NewDecoder returns a new decoder that reads from reader r using schema. NewDecoder(schema Schema, r io.Reader) *Decoder // DecoderOf returns the value decoder for a given schema and type. DecoderOf(schema Schema, typ reflect2.Type) ValDecoder // EncoderOf returns the value encoder for a given schema and type. EncoderOf(schema Schema, tpy reflect2.Type) ValEncoder // Register registers names to their types for resolution. All primitive types are pre-registered. Register(name string, obj any) }
API represents a frozen Config.
type ArraySchema ¶
type ArraySchema struct {
// contains filtered or unexported fields
}
ArraySchema is an Avro array type schema.
func NewArraySchema ¶
func NewArraySchema(items Schema, opts ...SchemaOption) *ArraySchema
NewArraySchema creates an array schema instance.
func (*ArraySchema) Fingerprint ¶
func (s *ArraySchema) Fingerprint() [32]byte
Fingerprint returns the SHA256 fingerprint of the schema.
func (*ArraySchema) FingerprintUsing ¶
func (s *ArraySchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (*ArraySchema) Items ¶
func (s *ArraySchema) Items() Schema
Items returns the items schema of an array.
func (*ArraySchema) MarshalJSON ¶
func (s *ArraySchema) MarshalJSON() ([]byte, error)
MarshalJSON marshals the schema to json.
func (*ArraySchema) String ¶
func (s *ArraySchema) String() string
String returns the canonical form of the schema.
type Config ¶
type Config struct { // TagKey is the struct tag key used when en/decoding structs. // This defaults to "avro". TagKey string // BlockLength is the length of blocks for maps and arrays. // This defaults to 100. BlockLength int // DisableBlockSizeHeader disables encoding of an array/map size in bytes. // Encoded array/map will be prefixed with only the number of elements in // contrast with default behavior which prefixes them with the number of elements // and the total number of bytes in the array/map. Both approaches are valid according to the // Avro specification, however not all decoders support the latter. DisableBlockSizeHeader bool // UnionResolutionError determines if an error will be returned // when a type cannot be resolved while decoding a union. UnionResolutionError bool // PartialUnionTypeResolution dictates if the union type resolution // should be attempted even when not all union types are registered. // When enabled, the underlying type will get resolved if it is registered // even if other types of the union are not. If resolution fails, logic // falls back to default union resolution behavior based on the value of // UnionResolutionError. PartialUnionTypeResolution bool // Disable caching layer for encoders and decoders, forcing them to get rebuilt on every // call to Marshal() and Unmarshal() DisableCaching bool // MaxByteSliceSize is the maximum size of `bytes` or `string` types the Reader will create, defaulting to 1MiB. // If this size is exceeded, the Reader returns an error. This can be disabled by setting a negative number. MaxByteSliceSize int }
Config customises how the codec should behave.
type DecimalLogicalSchema ¶
type DecimalLogicalSchema struct {
// contains filtered or unexported fields
}
DecimalLogicalSchema is a decimal logical type.
func NewDecimalLogicalSchema ¶
func NewDecimalLogicalSchema(prec, scale int) *DecimalLogicalSchema
NewDecimalLogicalSchema creates a new decimal logical schema instance.
func (*DecimalLogicalSchema) Precision ¶
func (s *DecimalLogicalSchema) Precision() int
Precision returns the precision of the decimal logical schema.
func (*DecimalLogicalSchema) Scale ¶
func (s *DecimalLogicalSchema) Scale() int
Scale returns the scale of the decimal logical schema.
func (*DecimalLogicalSchema) String ¶
func (s *DecimalLogicalSchema) String() string
String returns the canonical form of the logical schema.
func (*DecimalLogicalSchema) Type ¶
func (s *DecimalLogicalSchema) Type() LogicalType
Type returns the type of the logical schema.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads and decodes Avro values from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from reader r using schema s.
func NewDecoderForSchema ¶
NewDecoderForSchema returns a new decoder that reads from r using schema.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes Avro values to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w using schema s.
func NewEncoderForSchema ¶
NewEncoderForSchema returns a new encoder that writes to w using schema.
type EnumSchema ¶
type EnumSchema struct {
// contains filtered or unexported fields
}
EnumSchema is an Avro enum type schema.
func NewEnumSchema ¶
func NewEnumSchema(name, namespace string, symbols []string, opts ...SchemaOption) (*EnumSchema, error)
NewEnumSchema creates a new enum schema instance.
func (EnumSchema) Aliases ¶
func (n EnumSchema) Aliases() []string
Aliases returns the fully qualified aliases of a schema.
func (*EnumSchema) Default ¶
func (s *EnumSchema) Default() string
Default returns the default of an enum or an empty string.
func (*EnumSchema) Fingerprint ¶
func (s *EnumSchema) Fingerprint() [32]byte
Fingerprint returns the SHA256 fingerprint of the schema.
func (*EnumSchema) FingerprintUsing ¶
func (s *EnumSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (EnumSchema) FullName ¶
func (n EnumSchema) FullName() string
FullName returns the fully qualified name of a schema.
func (*EnumSchema) MarshalJSON ¶
func (s *EnumSchema) MarshalJSON() ([]byte, error)
MarshalJSON marshals the schema to json.
func (EnumSchema) Namespace ¶
func (n EnumSchema) Namespace() string
Namespace returns the namespace of a schema.
func (*EnumSchema) String ¶
func (s *EnumSchema) String() string
String returns the canonical form of the schema.
func (*EnumSchema) Symbols ¶
func (s *EnumSchema) Symbols() []string
Symbols returns the symbols of an enum.
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is an Avro record type field.
func NewField ¶
func NewField(name string, typ Schema, opts ...SchemaOption) (*Field, error)
NewField creates a new field instance.
func (*Field) Default ¶
Default returns the default of a field or nil.
The only time a nil default is valid is for a Null Type.
func (*Field) HasDefault ¶
HasDefault determines if the field has a default value.
func (*Field) MarshalJSON ¶
MarshalJSON marshals the schema to json.
type FingerprintType ¶
type FingerprintType string
FingerprintType is a fingerprinting algorithm.
const ( CRC64Avro FingerprintType = "CRC64-AVRO" MD5 FingerprintType = "MD5" SHA256 FingerprintType = "SHA256" )
Fingerprint type constants.
type FixedSchema ¶
type FixedSchema struct {
// contains filtered or unexported fields
}
FixedSchema is an Avro fixed type schema.
func NewFixedSchema ¶
func NewFixedSchema( name, namespace string, size int, logical LogicalSchema, opts ...SchemaOption, ) (*FixedSchema, error)
NewFixedSchema creates a new fixed schema instance.
func (FixedSchema) Aliases ¶
func (n FixedSchema) Aliases() []string
Aliases returns the fully qualified aliases of a schema.
func (*FixedSchema) Fingerprint ¶
func (s *FixedSchema) Fingerprint() [32]byte
Fingerprint returns the SHA256 fingerprint of the schema.
func (*FixedSchema) FingerprintUsing ¶
func (s *FixedSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (FixedSchema) FullName ¶
func (n FixedSchema) FullName() string
FullName returns the fully qualified name of a schema.
func (*FixedSchema) Logical ¶
func (s *FixedSchema) Logical() LogicalSchema
Logical returns the logical schema or nil.
func (*FixedSchema) MarshalJSON ¶
func (s *FixedSchema) MarshalJSON() ([]byte, error)
MarshalJSON marshals the schema to json.
func (FixedSchema) Namespace ¶
func (n FixedSchema) Namespace() string
Namespace returns the namespace of a schema.
func (*FixedSchema) Size ¶
func (s *FixedSchema) Size() int
Size returns the number of bytes of the fixed schema.
func (*FixedSchema) String ¶
func (s *FixedSchema) String() string
String returns the canonical form of the schema.
type LogicalDuration ¶
LogicalDuration represents the `duration` logical type, as defined in https://avro.apache.org/docs/1.11.1/specification/#duration
type LogicalSchema ¶
type LogicalSchema interface { // Type returns the type of the logical schema. Type() LogicalType // String returns the canonical form of the logical schema. String() string }
LogicalSchema represents an Avro schema with a logical type.
type LogicalType ¶
type LogicalType string
LogicalType is a schema logical type.
const ( Decimal LogicalType = "decimal" UUID LogicalType = "uuid" Date LogicalType = "date" TimeMillis LogicalType = "time-millis" TimeMicros LogicalType = "time-micros" TimestampMillis LogicalType = "timestamp-millis" TimestampMicros LogicalType = "timestamp-micros" Duration LogicalType = "duration" )
Schema logical type constants.
type LogicalTypeSchema ¶
type LogicalTypeSchema interface { // Logical returns the logical schema or nil. Logical() LogicalSchema }
LogicalTypeSchema represents a schema that can contain a logical type.
type MapSchema ¶
type MapSchema struct {
// contains filtered or unexported fields
}
MapSchema is an Avro map type schema.
func NewMapSchema ¶
func NewMapSchema(values Schema, opts ...SchemaOption) *MapSchema
NewMapSchema creates a map schema instance.
func (*MapSchema) Fingerprint ¶
Fingerprint returns the SHA256 fingerprint of the schema.
func (*MapSchema) FingerprintUsing ¶
func (s *MapSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (*MapSchema) MarshalJSON ¶
MarshalJSON marshals the schema to json.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message is an Avro protocol message.
func NewMessage ¶
func NewMessage(req *RecordSchema, resp Schema, errors *UnionSchema, oneWay bool, opts ...ProtocolOption) *Message
NewMessage creates a protocol message instance.
func (*Message) Errors ¶
func (m *Message) Errors() *UnionSchema
Errors returns the message errors union schema.
func (*Message) Request ¶
func (m *Message) Request() *RecordSchema
Request returns the message request schema.
type NamedSchema ¶
type NamedSchema interface { Schema PropertySchema // Name returns the name of the schema. Name() string // Namespace returns the namespace of a schema. Namespace() string // FullName returns the full qualified name of a schema. FullName() string }
NamedSchema represents a schema with a name.
type NullSchema ¶
type NullSchema struct {
// contains filtered or unexported fields
}
NullSchema is an Avro null type schema.
func (*NullSchema) Fingerprint ¶
func (s *NullSchema) Fingerprint() [32]byte
Fingerprint returns the SHA256 fingerprint of the schema.
func (*NullSchema) FingerprintUsing ¶
func (s *NullSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (*NullSchema) MarshalJSON ¶
func (s *NullSchema) MarshalJSON() ([]byte, error)
MarshalJSON marshals the schema to json.
func (*NullSchema) String ¶
func (s *NullSchema) String() string
String returns the canonical form of the schema.
type PrimitiveLogicalSchema ¶
type PrimitiveLogicalSchema struct {
// contains filtered or unexported fields
}
PrimitiveLogicalSchema is a logical type with no properties.
func NewPrimitiveLogicalSchema ¶
func NewPrimitiveLogicalSchema(typ LogicalType) *PrimitiveLogicalSchema
NewPrimitiveLogicalSchema creates a new primitive logical schema instance.
func (*PrimitiveLogicalSchema) String ¶
func (s *PrimitiveLogicalSchema) String() string
String returns the canonical form of the logical schema.
func (*PrimitiveLogicalSchema) Type ¶
func (s *PrimitiveLogicalSchema) Type() LogicalType
Type returns the type of the logical schema.
type PrimitiveSchema ¶
type PrimitiveSchema struct {
// contains filtered or unexported fields
}
PrimitiveSchema is an Avro primitive type schema.
func NewPrimitiveSchema ¶
func NewPrimitiveSchema(t Type, l LogicalSchema, opts ...SchemaOption) *PrimitiveSchema
NewPrimitiveSchema creates a new PrimitiveSchema.
func (*PrimitiveSchema) Fingerprint ¶
func (s *PrimitiveSchema) Fingerprint() [32]byte
Fingerprint returns the SHA256 fingerprint of the schema.
func (*PrimitiveSchema) FingerprintUsing ¶
func (s *PrimitiveSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (*PrimitiveSchema) Logical ¶
func (s *PrimitiveSchema) Logical() LogicalSchema
Logical returns the logical schema or nil.
func (*PrimitiveSchema) MarshalJSON ¶
func (s *PrimitiveSchema) MarshalJSON() ([]byte, error)
MarshalJSON marshals the schema to json.
func (*PrimitiveSchema) String ¶
func (s *PrimitiveSchema) String() string
String returns the canonical form of the schema.
func (*PrimitiveSchema) Type ¶
func (s *PrimitiveSchema) Type() Type
Type returns the type of the schema.
type PropertySchema ¶
PropertySchema represents a schema with properties.
type Protocol ¶
type Protocol struct {
// contains filtered or unexported fields
}
Protocol is an Avro protocol.
func MustParseProtocol ¶
MustParseProtocol parses an Avro protocol, panicing if there is an error.
func NewProtocol ¶
func NewProtocol( name, namepsace string, types []NamedSchema, messages map[string]*Message, opts ...ProtocolOption, ) (*Protocol, error)
NewProtocol creates a protocol instance.
func ParseProtocol ¶
ParseProtocol parses an Avro protocol.
func ParseProtocolFile ¶
ParseProtocolFile parses an Avro protocol from a file.
func (Protocol) Aliases ¶
func (n Protocol) Aliases() []string
Aliases returns the fully qualified aliases of a schema.
func (Protocol) FullName ¶
func (n Protocol) FullName() string
FullName returns the fully qualified name of a schema.
func (Protocol) Namespace ¶
func (n Protocol) Namespace() string
Namespace returns the namespace of a schema.
func (*Protocol) Types ¶
func (p *Protocol) Types() []NamedSchema
Types returns the types of the protocol.
type ProtocolOption ¶
type ProtocolOption func(*protocolConfig)
ProtocolOption is a function that sets a protocol option.
func WithProtoDoc ¶
func WithProtoDoc(doc string) ProtocolOption
WithProtoDoc sets the doc on a protocol.
func WithProtoProps ¶
func WithProtoProps(props map[string]any) ProtocolOption
WithProtoProps sets the properties on a protocol.
type Reader ¶
type Reader struct { Error error // contains filtered or unexported fields }
Reader is an Avro specific io.Reader.
func NewReader ¶
func NewReader(r io.Reader, bufSize int, opts ...ReaderFunc) *Reader
NewReader creates a new Reader.
func (*Reader) ReadArrayCB ¶
ReadArrayCB reads an array with a callback per item.
func (*Reader) ReadBlockHeader ¶
ReadBlockHeader reads a Block Header from the Reader.
func (*Reader) ReadDouble ¶
ReadDouble reads a Double from the Reader.
func (*Reader) ReadString ¶
ReadString reads a String from the Reader.
func (*Reader) ReadVal ¶
ReadVal parses Avro value and stores the result in the value pointed to by obj.
func (*Reader) ReportError ¶
ReportError record a error in iterator instance with current position.
func (*Reader) SkipNBytes ¶
SkipNBytes skips the given number of bytes in the reader.
type ReaderFunc ¶
type ReaderFunc func(r *Reader)
ReaderFunc is a function used to customize the Reader.
func WithReaderConfig ¶
func WithReaderConfig(cfg API) ReaderFunc
WithReaderConfig specifies the configuration to use with a reader.
type RecordSchema ¶
type RecordSchema struct {
// contains filtered or unexported fields
}
RecordSchema is an Avro record type schema.
func NewErrorRecordSchema ¶
func NewErrorRecordSchema(name, namespace string, fields []*Field, opts ...SchemaOption) (*RecordSchema, error)
NewErrorRecordSchema creates a new error record schema instance.
func NewRecordSchema ¶
func NewRecordSchema(name, namespace string, fields []*Field, opts ...SchemaOption) (*RecordSchema, error)
NewRecordSchema creates a new record schema instance.
func (RecordSchema) Aliases ¶
func (n RecordSchema) Aliases() []string
Aliases returns the fully qualified aliases of a schema.
func (*RecordSchema) Doc ¶
func (s *RecordSchema) Doc() string
Doc returns the documentation of a record.
func (*RecordSchema) Fields ¶
func (s *RecordSchema) Fields() []*Field
Fields returns the fields of a record.
func (*RecordSchema) Fingerprint ¶
func (s *RecordSchema) Fingerprint() [32]byte
Fingerprint returns the SHA256 fingerprint of the schema.
func (*RecordSchema) FingerprintUsing ¶
func (s *RecordSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (RecordSchema) FullName ¶
func (n RecordSchema) FullName() string
FullName returns the fully qualified name of a schema.
func (*RecordSchema) IsError ¶
func (s *RecordSchema) IsError() bool
IsError determines is this is an error record.
func (*RecordSchema) MarshalJSON ¶
func (s *RecordSchema) MarshalJSON() ([]byte, error)
MarshalJSON marshals the schema to json.
func (RecordSchema) Namespace ¶
func (n RecordSchema) Namespace() string
Namespace returns the namespace of a schema.
func (*RecordSchema) String ¶
func (s *RecordSchema) String() string
String returns the canonical form of the schema.
type RefSchema ¶
type RefSchema struct {
// contains filtered or unexported fields
}
RefSchema is a reference to a named Avro schema.
func NewRefSchema ¶
func NewRefSchema(schema NamedSchema) *RefSchema
NewRefSchema creates a ref schema instance.
func (*RefSchema) Fingerprint ¶
Fingerprint returns the SHA256 fingerprint of the schema.
func (*RefSchema) FingerprintUsing ¶
func (s *RefSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (*RefSchema) MarshalJSON ¶
MarshalJSON marshals the schema to json.
func (*RefSchema) Schema ¶
func (s *RefSchema) Schema() NamedSchema
Schema returns the schema being referenced.
type Schema ¶
type Schema interface { // Type returns the type of the schema. Type() Type // String returns the canonical form of the schema. String() string // Fingerprint returns the SHA256 fingerprint of the schema. Fingerprint() [32]byte // FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. FingerprintUsing(FingerprintType) ([]byte, error) }
Schema represents an Avro schema.
func ParseBytes ¶
ParseBytes parses a schema byte slice.
func ParseBytesWithCache ¶
func ParseBytesWithCache(schema []byte, namespace string, cache *SchemaCache) (Schema, error)
ParseBytesWithCache parses a schema byte slice using the given namespace and schema cache.
func ParseFiles ¶
ParseFiles parses the schemas in the files, in the order they appear, returning the last schema.
This is useful when your schemas rely on other schemas.
func ParseValue ¶
func ParseWithCache ¶
func ParseWithCache(schema, namespace string, cache *SchemaCache) (Schema, error)
ParseWithCache parses a schema string using the given namespace and schema cache.
type SchemaCache ¶
type SchemaCache struct {
// contains filtered or unexported fields
}
SchemaCache is a cache of schemas.
func (*SchemaCache) Add ¶
func (c *SchemaCache) Add(name string, schema Schema)
Add adds a schema to the cache with the given name.
func (*SchemaCache) Get ¶
func (c *SchemaCache) Get(name string) Schema
Get returns the Schema if it exists.
type SchemaCompatibility ¶
type SchemaCompatibility struct {
// contains filtered or unexported fields
}
SchemaCompatibility determines the compatibility of schemas.
func NewSchemaCompatibility ¶
func NewSchemaCompatibility() *SchemaCompatibility
NewSchemaCompatibility creates a new schema compatibility instance.
func (*SchemaCompatibility) Compatible ¶
func (c *SchemaCompatibility) Compatible(reader, writer Schema) error
Compatible determines the compatibility if the reader and writer schemas.
type SchemaOption ¶
type SchemaOption func(*schemaConfig)
SchemaOption is a function that sets a schema option.
func WithAliases ¶
func WithAliases(aliases []string) SchemaOption
WithAliases sets the aliases on a schema.
func WithProps ¶
func WithProps(props map[string]any) SchemaOption
WithProps sets the properties on a schema.
type Type ¶
type Type string
Type is a schema type.
const ( Record Type = "record" Error Type = "error" Ref Type = "<ref>" Enum Type = "enum" Array Type = "array" Map Type = "map" Union Type = "union" Fixed Type = "fixed" String Type = "string" Bytes Type = "bytes" Int Type = "int" Long Type = "long" Float Type = "float" Double Type = "double" Boolean Type = "boolean" Null Type = "null" Raw Type = "raw" )
Schema type constants.
type TypeResolver ¶
type TypeResolver struct {
// contains filtered or unexported fields
}
TypeResolver resolves types by name.
func NewTypeResolver ¶
func NewTypeResolver() *TypeResolver
NewTypeResolver creates a new type resolver with all primitive types registered.
func (*TypeResolver) Name ¶
func (r *TypeResolver) Name(typ reflect2.Type) ([]string, error)
Name gets the name for a type, or an error.
func (*TypeResolver) Register ¶
func (r *TypeResolver) Register(name string, obj any)
Register registers names to their types for resolution.
type UnionSchema ¶
type UnionSchema struct {
// contains filtered or unexported fields
}
UnionSchema is an Avro union type schema.
func NewUnionSchema ¶
func NewUnionSchema(types []Schema) (*UnionSchema, error)
NewUnionSchema creates a union schema instance.
func (*UnionSchema) Fingerprint ¶
func (s *UnionSchema) Fingerprint() [32]byte
Fingerprint returns the SHA256 fingerprint of the schema.
func (*UnionSchema) FingerprintUsing ¶
func (s *UnionSchema) FingerprintUsing(typ FingerprintType) ([]byte, error)
FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error.
func (*UnionSchema) Indices ¶
func (s *UnionSchema) Indices() (null, typ int)
Indices returns the index of the null and type schemas for a nullable schema. For non-nullable schemas 0 is returned for both.
func (*UnionSchema) MarshalJSON ¶
func (s *UnionSchema) MarshalJSON() ([]byte, error)
MarshalJSON marshals the schema to json.
func (*UnionSchema) Nullable ¶
func (s *UnionSchema) Nullable() bool
Nullable returns the Schema if the union is nullable, otherwise nil.
func (*UnionSchema) String ¶
func (s *UnionSchema) String() string
String returns the canonical form of the schema.
func (*UnionSchema) Types ¶
func (s *UnionSchema) Types() Schemas
Types returns the types of a union.
type Unmarshaler ¶ added in v1.2.0
type ValDecoder ¶
ValDecoder represents an internal value decoder.
You should never use ValDecoder directly.
type ValEncoder ¶
ValEncoder represents an internal value encoder.
You should never use ValEncoder directly.
type Writer ¶
type Writer struct { Error error // contains filtered or unexported fields }
Writer is an Avro specific io.Writer.
func NewWriter ¶
func NewWriter(out io.Writer, bufSize int, opts ...WriterFunc) *Writer
NewWriter creates a new Writer.
func (*Writer) WriteBlockCB ¶
WriteBlockCB writes a block using the callback.
func (*Writer) WriteBlockHeader ¶
WriteBlockHeader writes a Block Header to the Writer.
func (*Writer) WriteBytes ¶
WriteBytes writes Bytes to the Writer.
func (*Writer) WriteDouble ¶
WriteDouble writes a Double to the Writer.
func (*Writer) WriteFloat ¶
WriteFloat writes a Float to the Writer.
func (*Writer) WriteString ¶
WriteString reads a String to the Writer.
type WriterFunc ¶
type WriterFunc func(w *Writer)
WriterFunc is a function used to customize the Writer.
func WithWriterConfig ¶
func WithWriterConfig(cfg API) WriterFunc
WithWriterConfig specifies the configuration to use with a writer.
Source Files ¶
- codec.go
- codec_array.go
- codec_dynamic.go
- codec_enum.go
- codec_fixed.go
- codec_map.go
- codec_marshaler.go
- codec_native.go
- codec_ptr.go
- codec_raw.go
- codec_record.go
- codec_skip.go
- codec_union.go
- config.go
- decoder.go
- encoder.go
- noescape.go
- protocol.go
- reader.go
- reader_generic.go
- reader_skip.go
- resolver.go
- schema.go
- schema_array.go
- schema_compatibility.go
- schema_map.go
- schema_parse.go
- schema_ptr.go
- schema_slice.go
- schema_struct.go
- schema_value.go
- schema_walk.go
- types.go
- writer.go