package avro

Import Path
	github.com/hamba/avro/v2 (on go.dev)

Dependency Relation
	imports 26 packages, and imported by 2 packages


Code Examples { schema := avro.MustParse(`{ "type": "record", "name": "simple", "namespace": "org.hamba.avro", "fields" : [ {"name": "a", "type": "long"}, {"name": "b", "type": "string"} ] }`) type SimpleRecord struct { A int64 `avro:"a"` B string `avro:"b"` } simple := SimpleRecord{A: 27, B: "foo"} b, err := avro.Marshal(schema, simple) if err != nil { fmt.Println("error:", err) } fmt.Println(b) } { schema := `{ "type": "record", "name": "simple", "namespace": "org.hamba.avro", "fields" : [ {"name": "a", "type": "long"}, {"name": "b", "type": "string"} ] }` type SimpleRecord struct { A int64 `avro:"a"` B string `avro:"b"` } r := bytes.NewReader([]byte{}) decoder, err := avro.NewDecoder(schema, r) if err != nil { fmt.Println("error:", err) } simple := SimpleRecord{} if err := decoder.Decode(&simple); err != nil { fmt.Println("error:", err) } fmt.Printf("%+v", simple) } { schema := avro.MustParse(`{ "type": "record", "name": "simple", "namespace": "org.hamba.avro", "fields" : [ {"name": "a", "type": "long"}, {"name": "b", "type": "string"} ] }`) type SimpleRecord struct { A int64 `avro:"a"` B string `avro:"b"` } r := bytes.NewReader([]byte{0x36, 0x06, 0x66, 0x6F, 0x6F}) decoder := avro.NewDecoderForSchema(schema, r) simple := SimpleRecord{} if err := decoder.Decode(&simple); err != nil { fmt.Println("error:", err) } fmt.Printf("%+v", simple) } { schema := `{ "type": "record", "name": "simple", "namespace": "org.hamba.avro", "fields" : [ {"name": "a", "type": "long"}, {"name": "b", "type": "string"} ] }` type SimpleRecord struct { A int64 `avro:"a"` B string `avro:"b"` } w := &bytes.Buffer{} encoder, err := avro.NewEncoder(schema, w) if err != nil { fmt.Println("error:", err) } simple := SimpleRecord{A: 27, B: "foo"} if err := encoder.Encode(simple); err != nil { fmt.Println("error:", err) } fmt.Println(w.Bytes()) } { schema := avro.MustParse(`{ "type": "record", "name": "simple", "namespace": "org.hamba.avro", "fields" : [ {"name": "a", "type": "long"}, {"name": "b", "type": "string"} ] }`) type SimpleRecord struct { A int64 `avro:"a"` B string `avro:"b"` } w := &bytes.Buffer{} encoder := avro.NewEncoderForSchema(schema, w) simple := SimpleRecord{A: 27, B: "foo"} if err := encoder.Encode(simple); err != nil { fmt.Println("error:", err) } fmt.Println(w.Bytes()) } { schema, err := avro.Parse(`{ "type": "record", "name": "simple", "namespace": "org.hamba.avro", "fields" : [ {"name": "a", "type": "long"}, {"name": "b", "type": "string"} ] }`) if err != nil { log.Fatal(err) } fmt.Println(schema.Type()) } { data := []byte{0x02, 0x02} schema := avro.MustParse(`["null", {"type":"enum", "name": "test", "symbols": ["A", "B"]}]`) avro.Register("test", "") var result any err := avro.Unmarshal(schema, data, &result) if err != nil { log.Fatal(err) } fmt.Println(result) } { schema := avro.MustParse(`{ "type": "record", "name": "simple", "namespace": "org.hamba.avro", "fields" : [ {"name": "a", "type": "long"}, {"name": "b", "type": "string"} ] }`) type SimpleRecord struct { A int64 `avro:"a"` B string `avro:"b"` } data := []byte{0x36, 0x06, 0x66, 0x6F, 0x6F} simple := SimpleRecord{} if err := avro.Unmarshal(schema, data, &simple); err != nil { fmt.Println("error:", err) } fmt.Printf("%+v", simple) } package main import ( "fmt" "log" "github.com/hamba/avro/v2" ) var Schema = `{ "type": "record", "name": "simple", "namespace": "org.hamba.avro", "fields" : [ {"name": "a", "type": "long"}, {"name": "b", "type": "string"} ] }` type SimpleRecord struct { A int64 `avro:"a"` B string `avro:"b"` } func main() { schema, err := avro.Parse(Schema) if err != nil { log.Fatal(err) } in := SimpleRecord{A: 27, B: "foo"} data, err := avro.Marshal(schema, in) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", data) out := SimpleRecord{} err = avro.Unmarshal(schema, data, &out) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", out) }
Package-Level Type Names (total 45)
/* sort by: | */
Action is a field action used during decoding process. const FieldIgnore const FieldSetDefault
API represents a frozen Config. DecoderOf returns the value decoder for a given schema and type. EncoderOf returns the value encoder for a given schema and type. Marshal returns the Avro encoding of v. NewDecoder returns a new decoder that reads from reader r using schema. NewEncoder returns a new encoder that writes to w using schema. Register registers names to their types for resolution. All primitive types are pre-registered. RegisterTypeConverters registers type conversion functions. 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. func Config.Freeze() API func WithReaderConfig(cfg API) ReaderFunc func WithWriterConfig(cfg API) WriterFunc func github.com/hamba/avro/v2/ocf.WithDecoderConfig(wCfg API) ocf.DecoderFunc func github.com/hamba/avro/v2/ocf.WithEncodingConfig(wCfg API) ocf.EncoderFunc var DefaultConfig
ArraySchema is an Avro array type schema. CacheFingerprint returns unique identity of the schema. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. Items returns the items schema of an array. MarshalJSON marshals the schema to json. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. String returns the canonical form of the schema. Type returns the type of the schema. ArraySchema : PropertySchema *ArraySchema : Schema *ArraySchema : github.com/goccy/go-json.Marshaler *ArraySchema : encoding/json.Marshaler *ArraySchema : expvar.Var *ArraySchema : fmt.Stringer func NewArraySchema(items Schema, opts ...SchemaOption) *ArraySchema
Config customises how the codec should behave. BlockLength is the length of blocks for maps and arrays. This defaults to 100. 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. Disable caching layer for encoders and decoders, forcing them to get rebuilt on every call to Marshal() and Unmarshal() 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. MaxSliceAllocSize is the maximum size that the decoder will allocate, set to the max heap allocation size by default. If this size is exceeded, the decoder returns an error. 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. TagKey is the struct tag key used when en/decoding structs. This defaults to "avro". UnionResolutionError determines if an error will be returned when a type cannot be resolved while decoding a union. Freeze makes the configuration immutable.
DecimalLogicalSchema is a decimal logical type. Precision returns the precision of the decimal logical schema. Scale returns the scale of the decimal logical schema. String returns the canonical form of the logical schema. Type returns the type of the logical schema. *DecimalLogicalSchema : LogicalSchema *DecimalLogicalSchema : expvar.Var *DecimalLogicalSchema : fmt.Stringer func NewDecimalLogicalSchema(prec, scale int) *DecimalLogicalSchema
Decoder reads and decodes Avro values from an input stream. Decode reads the next Avro encoded value from its input and stores it in the value pointed to by v. *Decoder : github.com/grpc-ecosystem/grpc-gateway/v2/runtime.Decoder func NewDecoder(s string, r io.Reader) (*Decoder, error) func NewDecoderForSchema(schema Schema, reader io.Reader) *Decoder func API.NewDecoder(schema Schema, r io.Reader) *Decoder
Encoder writes Avro values to an output stream. Encode writes the Avro encoding of v to the stream. *Encoder : github.com/grpc-ecosystem/grpc-gateway/v2/runtime.Encoder *Encoder : go.uber.org/zap/zapcore.ReflectedEncoder func NewEncoder(s string, w io.Writer) (*Encoder, error) func NewEncoderForSchema(schema Schema, w io.Writer) *Encoder func API.NewEncoder(schema Schema, w io.Writer) *Encoder
EnumSchema is an Avro enum type schema. Aliases returns the fully qualified aliases of a schema. CacheFingerprint returns unique identity of the schema. Default returns the default of an enum or an empty string. Doc returns the schema doc. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. FullName returns the fully qualified name of a schema. HasDefault determines if the schema has a default value. MarshalJSON marshals the schema to json. Name returns the name of a schema. Namespace returns the namespace of a schema. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. String returns the canonical form of the schema. Symbol returns the symbol for the given index. It might return the default value in the context of write-read schema resolution. Symbols returns the symbols of an enum. Type returns the type of the schema. *EnumSchema : NamedSchema EnumSchema : PropertySchema *EnumSchema : Schema *EnumSchema : github.com/goccy/go-json.Marshaler *EnumSchema : github.com/K-Phoen/grabana/datasource.Datasource EnumSchema : github.com/polarsignals/frostdb/query/logicalplan.Named *EnumSchema : encoding/json.Marshaler *EnumSchema : expvar.Var *EnumSchema : fmt.Stringer func NewEnumSchema(name, namespace string, symbols []string, opts ...SchemaOption) (*EnumSchema, error)
Field is an Avro record type field. Aliases return the field aliases. Default returns the default of a field or nil. The only time a nil default is valid is for a Null Type. Doc returns the documentation of a field. HasDefault determines if the field has a default value. MarshalJSON marshals the schema to json. Name returns the name of a field. Order returns the field order. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. String returns the canonical form of a field. Type returns the schema of a field. Field : PropertySchema *Field : github.com/goccy/go-json.Marshaler *Field : github.com/K-Phoen/grabana/datasource.Datasource *Field : github.com/polarsignals/frostdb/query/logicalplan.Named *Field : encoding/json.Marshaler *Field : expvar.Var *Field : fmt.Stringer func NewField(name string, typ Schema, opts ...SchemaOption) (*Field, error) func (*RecordSchema).Fields() []*Field func NewErrorRecordSchema(name, namespace string, fields []*Field, opts ...SchemaOption) (*RecordSchema, error) func NewRecordSchema(name, namespace string, fields []*Field, opts ...SchemaOption) (*RecordSchema, error)
FingerprintType is a fingerprinting algorithm. func (*ArraySchema).FingerprintUsing(typ FingerprintType) ([]byte, error) func (*EnumSchema).FingerprintUsing(typ FingerprintType) ([]byte, error) func (*FixedSchema).FingerprintUsing(typ FingerprintType) ([]byte, error) func (*MapSchema).FingerprintUsing(typ FingerprintType) ([]byte, error) func NamedSchema.FingerprintUsing(FingerprintType) ([]byte, error) func (*NullSchema).FingerprintUsing(typ FingerprintType) ([]byte, error) func (*PrimitiveSchema).FingerprintUsing(typ FingerprintType) ([]byte, error) func (*RecordSchema).FingerprintUsing(typ FingerprintType) ([]byte, error) func (*RefSchema).FingerprintUsing(typ FingerprintType) ([]byte, error) func Schema.FingerprintUsing(FingerprintType) ([]byte, error) func (*UnionSchema).FingerprintUsing(typ FingerprintType) ([]byte, error) const CRC64Avro const CRC64AvroLE const MD5 const SHA256
FixedSchema is an Avro fixed type schema. Aliases returns the fully qualified aliases of a schema. CacheFingerprint returns unique identity of the schema. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. FullName returns the fully qualified name of a schema. Logical returns the logical schema or nil. MarshalJSON marshals the schema to json. Name returns the name of a schema. Namespace returns the namespace of a schema. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. Size returns the number of bytes of the fixed schema. String returns the canonical form of the schema. Type returns the type of the schema. *FixedSchema : LogicalTypeSchema *FixedSchema : NamedSchema FixedSchema : PropertySchema *FixedSchema : Schema *FixedSchema : github.com/goccy/go-json.Marshaler *FixedSchema : github.com/gogo/protobuf/proto.Sizer *FixedSchema : github.com/K-Phoen/grabana/datasource.Datasource FixedSchema : github.com/polarsignals/frostdb/query/logicalplan.Named *FixedSchema : encoding/json.Marshaler *FixedSchema : expvar.Var *FixedSchema : fmt.Stringer func NewFixedSchema(name, namespace string, size int, logical LogicalSchema, opts ...SchemaOption) (*FixedSchema, error)
LogicalDuration represents the `duration` logical type, as defined in https://avro.apache.org/docs/1.11.1/specification/#duration Days uint32 Milliseconds uint32 Months uint32
LogicalSchema represents an Avro schema with a logical type. String returns the canonical form of the logical schema. Type returns the type of the logical schema. *DecimalLogicalSchema *PrimitiveLogicalSchema LogicalSchema : expvar.Var LogicalSchema : fmt.Stringer func (*FixedSchema).Logical() LogicalSchema func LogicalTypeSchema.Logical() LogicalSchema func (*PrimitiveSchema).Logical() LogicalSchema func NewFixedSchema(name, namespace string, size int, logical LogicalSchema, opts ...SchemaOption) (*FixedSchema, error) func NewPrimitiveSchema(t Type, l LogicalSchema, opts ...SchemaOption) *PrimitiveSchema
LogicalType is a schema logical type. func (*DecimalLogicalSchema).Type() LogicalType func LogicalSchema.Type() LogicalType func (*PrimitiveLogicalSchema).Type() LogicalType func TypeConversionFuncs.LogicalType() LogicalType func TypeConverter.LogicalType() LogicalType func NewPrimitiveLogicalSchema(typ LogicalType) *PrimitiveLogicalSchema const Date const Decimal const Duration const LocalTimestampMicros const LocalTimestampMillis const TimeMicros const TimeMillis const TimestampMicros const TimestampMillis const UUID
LogicalTypeSchema represents a schema that can contain a logical type. Logical returns the logical schema or nil. *FixedSchema *PrimitiveSchema
MapSchema is an Avro map type schema. CacheFingerprint returns unique identity of the schema. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. MarshalJSON marshals the schema to json. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. String returns the canonical form of the schema. Type returns the type of the schema. Values returns the values schema of a map. MapSchema : PropertySchema *MapSchema : Schema *MapSchema : github.com/goccy/go-json.Marshaler *MapSchema : encoding/json.Marshaler *MapSchema : expvar.Var *MapSchema : fmt.Stringer func NewMapSchema(values Schema, opts ...SchemaOption) *MapSchema
Message is an Avro protocol message. Doc returns the message doc. Errors returns the message errors union schema. OneWay determines of the message is a one way message. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. Request returns the message request schema. Response returns the message response schema. String returns the canonical form of the message. Message : PropertySchema *Message : expvar.Var *Message : fmt.Stringer func NewMessage(req *RecordSchema, resp Schema, errors *UnionSchema, oneWay bool, opts ...ProtocolOption) *Message func (*Protocol).Message(name string) *Message func NewProtocol(name, namepsace string, types []NamedSchema, messages map[string]*Message, opts ...ProtocolOption) (*Protocol, error)
NamedSchema represents a schema with a name. Aliases returns the full qualified aliases of a schema. CacheFingerprint returns the unique identity of the schema. This returns a unique identity for schemas resolved from a writer schema, otherwise it returns the schemas Fingerprint. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. FullName returns the full qualified name of a schema. Name returns the name of the schema. Namespace returns the namespace of a schema. Prop gets a property from the schema. String returns the canonical form of the schema. Type returns the type of the schema. *EnumSchema *FixedSchema *RecordSchema NamedSchema : PropertySchema NamedSchema : Schema NamedSchema : github.com/polarsignals/frostdb/query/logicalplan.Named NamedSchema : expvar.Var NamedSchema : fmt.Stringer func (*Protocol).Types() []NamedSchema func (*RefSchema).Schema() NamedSchema func NewProtocol(name, namepsace string, types []NamedSchema, messages map[string]*Message, opts ...ProtocolOption) (*Protocol, error) func NewRefSchema(schema NamedSchema) *RefSchema
NullSchema is an Avro null type schema. CacheFingerprint returns unique identity of the schema. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. MarshalJSON marshals the schema to json. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. String returns the canonical form of the schema. Type returns the type of the schema. NullSchema : PropertySchema *NullSchema : Schema *NullSchema : github.com/goccy/go-json.Marshaler *NullSchema : encoding/json.Marshaler *NullSchema : expvar.Var *NullSchema : fmt.Stringer func NewNullSchema(opts ...SchemaOption) *NullSchema
Order is a field order. func (*Field).Order() Order func WithOrder(order Order) SchemaOption const Asc const Desc const Ignore
PrimitiveLogicalSchema is a logical type with no properties. String returns the canonical form of the logical schema. Type returns the type of the logical schema. *PrimitiveLogicalSchema : LogicalSchema *PrimitiveLogicalSchema : expvar.Var *PrimitiveLogicalSchema : fmt.Stringer func NewPrimitiveLogicalSchema(typ LogicalType) *PrimitiveLogicalSchema
PrimitiveSchema is an Avro primitive type schema. CacheFingerprint returns unique identity of the schema. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. Logical returns the logical schema or nil. MarshalJSON marshals the schema to json. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. String returns the canonical form of the schema. Type returns the type of the schema. *PrimitiveSchema : LogicalTypeSchema PrimitiveSchema : PropertySchema *PrimitiveSchema : Schema *PrimitiveSchema : github.com/goccy/go-json.Marshaler *PrimitiveSchema : encoding/json.Marshaler *PrimitiveSchema : expvar.Var *PrimitiveSchema : fmt.Stringer func NewPrimitiveSchema(t Type, l LogicalSchema, opts ...SchemaOption) *PrimitiveSchema
PropertySchema represents a schema with properties. Prop gets a property from the schema. ArraySchema EnumSchema Field FixedSchema MapSchema Message NamedSchema (interface) NullSchema PrimitiveSchema Protocol RecordSchema
Protocol is an Avro protocol. Aliases returns the fully qualified aliases of a schema. Doc returns the protocol doc. FullName returns the fully qualified name of a schema. Hash returns the MD5 hash of the protocol. Message returns a message with the given name or nil. Name returns the name of a schema. Namespace returns the namespace of a schema. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. String returns the canonical form of the protocol. Types returns the types of the protocol. Protocol : PropertySchema Protocol : github.com/polarsignals/frostdb/query/logicalplan.Named *Protocol : expvar.Var *Protocol : fmt.Stringer func MustParseProtocol(protocol string) *Protocol func NewProtocol(name, namepsace string, types []NamedSchema, messages map[string]*Message, opts ...ProtocolOption) (*Protocol, error) func ParseProtocol(protocol string) (*Protocol, error) func ParseProtocolFile(path string) (*Protocol, error)
ProtocolOption is a function that sets a protocol option. func WithProtoDoc(doc string) ProtocolOption func WithProtoProps(props map[string]any) ProtocolOption func NewMessage(req *RecordSchema, resp Schema, errors *UnionSchema, oneWay bool, opts ...ProtocolOption) *Message func NewProtocol(name, namepsace string, types []NamedSchema, messages map[string]*Message, opts ...ProtocolOption) (*Protocol, error)
Reader is an Avro specific io.Reader. Error error Peek returns the next byte in the buffer. The Reader Error will be io.EOF if no next byte exists. Read reads data into the given bytes. ReadArrayCB reads an array with a callback per item. ReadBlockHeader reads a Block Header from the Reader. ReadBool reads a Bool from the Reader. ReadBytes reads Bytes from the Reader. ReadDouble reads a Double from the Reader. ReadFloat reads a Float from the Reader. ReadInt reads an Int from the Reader. ReadLong reads a Long from the Reader. ReadMapCB reads an array with a callback per item. ReadNext reads the next Avro element as a generic interface. ReadString reads a String from the Reader. ReadVal parses Avro value and stores the result in the value pointed to by obj. ReportError record an error in iterator instance with current position. Reset resets a Reader with a new byte array attached. SkipBool skips a Bool in the reader. SkipBytes skips Bytes in the reader. SkipDouble skips a Double in the reader. SkipFloat skips a Float in the reader. SkipInt skips an Int in the reader. SkipLong skips a Long in the reader. SkipNBytes skips the given number of bytes in the reader. SkipString skips a String in the reader. func NewReader(r io.Reader, bufSize int, opts ...ReaderFunc) *Reader func (*Reader).Reset(b []byte) *Reader func ValDecoder.Decode(ptr unsafe.Pointer, r *Reader)
ReaderFunc is a function used to customize the Reader. func WithReaderConfig(cfg API) ReaderFunc func NewReader(r io.Reader, bufSize int, opts ...ReaderFunc) *Reader
RecordSchema is an Avro record type schema. Aliases returns the fully qualified aliases of a schema. CacheFingerprint returns unique identity of the schema. Doc returns the documentation of a record. Fields returns the fields of a record. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. FullName returns the fully qualified name of a schema. IsError determines is this is an error record. MarshalJSON marshals the schema to json. Name returns the name of a schema. Namespace returns the namespace of a schema. Prop gets a property from the schema. Props returns a map that contains all schema custom properties. Any accidental change to the returned map will directly modify the schema custom properties. String returns the canonical form of the schema. Type returns the type of the schema. *RecordSchema : NamedSchema RecordSchema : PropertySchema *RecordSchema : Schema *RecordSchema : github.com/goccy/go-json.Marshaler *RecordSchema : github.com/K-Phoen/grabana/datasource.Datasource RecordSchema : github.com/polarsignals/frostdb/query/logicalplan.Named *RecordSchema : encoding/json.Marshaler *RecordSchema : expvar.Var *RecordSchema : fmt.Stringer func NewErrorRecordSchema(name, namespace string, fields []*Field, opts ...SchemaOption) (*RecordSchema, error) func NewRecordSchema(name, namespace string, fields []*Field, opts ...SchemaOption) (*RecordSchema, error) func (*Message).Request() *RecordSchema func NewMessage(req *RecordSchema, resp Schema, errors *UnionSchema, oneWay bool, opts ...ProtocolOption) *Message
RefSchema is a reference to a named Avro schema. CacheFingerprint returns unique identity of the schema. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. MarshalJSON marshals the schema to json. Schema returns the schema being referenced. String returns the canonical form of the schema. Type returns the type of the schema. *RefSchema : Schema *RefSchema : github.com/goccy/go-json.Marshaler *RefSchema : encoding/json.Marshaler *RefSchema : expvar.Var *RefSchema : fmt.Stringer func NewRefSchema(schema NamedSchema) *RefSchema
Schema represents an Avro schema. CacheFingerprint returns the unique identity of the schema. This returns a unique identity for schemas resolved from a writer schema, otherwise it returns the schemas Fingerprint. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. String returns the canonical form of the schema. Type returns the type of the schema. *ArraySchema *EnumSchema *FixedSchema *MapSchema NamedSchema (interface) *NullSchema *PrimitiveSchema *RecordSchema *RefSchema *UnionSchema Schema : expvar.Var Schema : fmt.Stringer 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 ParseWithCache(schema, namespace string, cache *SchemaCache) (Schema, error) func (*ArraySchema).Items() Schema func (*Field).Type() Schema func (*MapSchema).Values() Schema func (*Message).Response() Schema func (*SchemaCache).Get(name string) Schema func (*SchemaCompatibility).Resolve(reader, writer Schema) (Schema, error) func Schemas.Get(name string) (Schema, int) func github.com/hamba/avro/v2/ocf.(*Decoder).Schema() Schema func Marshal(schema Schema, v any) ([]byte, error) func NewArraySchema(items Schema, opts ...SchemaOption) *ArraySchema func NewDecoderForSchema(schema Schema, reader io.Reader) *Decoder func NewEncoderForSchema(schema Schema, w io.Writer) *Encoder func NewField(name string, typ Schema, opts ...SchemaOption) (*Field, error) func NewMapSchema(values Schema, opts ...SchemaOption) *MapSchema func NewMessage(req *RecordSchema, resp Schema, errors *UnionSchema, oneWay bool, opts ...ProtocolOption) *Message func NewUnionSchema(types []Schema, opts ...SchemaOption) (*UnionSchema, error) func Unmarshal(schema Schema, data []byte, v any) error func API.DecoderOf(schema Schema, typ reflect2.Type) ValDecoder func API.EncoderOf(schema Schema, typ reflect2.Type) ValEncoder func API.Marshal(schema Schema, v any) ([]byte, error) func API.NewDecoder(schema Schema, r io.Reader) *Decoder func API.NewEncoder(schema Schema, w io.Writer) *Encoder func API.Unmarshal(schema Schema, data []byte, v any) error func (*Reader).ReadNext(schema Schema) any func (*Reader).ReadVal(schema Schema, obj any) func (*SchemaCache).Add(name string, schema Schema) func (*SchemaCompatibility).Compatible(reader, writer Schema) error func (*SchemaCompatibility).Resolve(reader, writer Schema) (Schema, error) func TypeConversionFuncs.DecodeTypeConvert(in any, schema Schema) (any, error) func TypeConversionFuncs.EncodeTypeConvert(in any, schema Schema) (any, error) func TypeConverter.DecodeTypeConvert(in any, schema Schema) (any, error) func TypeConverter.EncodeTypeConvert(in any, schema Schema) (any, error) func (*TypeConverters).DecodeTypeConvert(in any, schema Schema) (any, error) func (*TypeConverters).EncodeTypeConvert(in any, schema Schema) (any, error) func (*Writer).WriteVal(schema Schema, val any) func github.com/hamba/avro/v2/ocf.NewEncoderWithSchema(schema Schema, w io.Writer, opts ...ocf.EncoderFunc) (*ocf.Encoder, error) var github.com/hamba/avro/v2/ocf.HeaderSchema
SchemaCache is a cache of schemas. Add adds a schema to the cache with the given name. AddAll adds all schemas from the given cache to the current cache. Get returns the Schema if it exists. func ParseBytesWithCache(schema []byte, namespace string, cache *SchemaCache) (Schema, error) func ParseWithCache(schema, namespace string, cache *SchemaCache) (Schema, error) func (*SchemaCache).AddAll(cache *SchemaCache) func github.com/hamba/avro/v2/ocf.WithDecoderSchemaCache(cache *SchemaCache) ocf.DecoderFunc func github.com/hamba/avro/v2/ocf.WithEncoderSchemaCache(cache *SchemaCache) ocf.EncoderFunc var DefaultSchemaCache *SchemaCache
SchemaCompatibility determines the compatibility of schemas. Compatible determines the compatibility if the reader and writer schemas. Resolve returns a composite schema that allows decoding data written by the writer schema, and makes necessary adjustments to support the reader schema. It fails if the writer and reader schemas are not compatible. func NewSchemaCompatibility() *SchemaCompatibility
SchemaOption is a function that sets a schema option. func WithAliases(aliases []string) SchemaOption func WithDefault(def any) SchemaOption func WithDoc(doc string) SchemaOption func WithOrder(order Order) SchemaOption func WithProps(props map[string]any) SchemaOption func NewArraySchema(items Schema, opts ...SchemaOption) *ArraySchema func NewEnumSchema(name, namespace string, symbols []string, opts ...SchemaOption) (*EnumSchema, error) func NewErrorRecordSchema(name, namespace string, fields []*Field, opts ...SchemaOption) (*RecordSchema, error) func NewField(name string, typ Schema, opts ...SchemaOption) (*Field, error) func NewFixedSchema(name, namespace string, size int, logical LogicalSchema, opts ...SchemaOption) (*FixedSchema, error) func NewMapSchema(values Schema, opts ...SchemaOption) *MapSchema func NewNullSchema(opts ...SchemaOption) *NullSchema func NewPrimitiveSchema(t Type, l LogicalSchema, opts ...SchemaOption) *PrimitiveSchema func NewRecordSchema(name, namespace string, fields []*Field, opts ...SchemaOption) (*RecordSchema, error) func NewUnionSchema(types []Schema, opts ...SchemaOption) (*UnionSchema, error)
Schemas is a slice of Schemas. Get gets a schema and position by type or name if it is a named schema. func (*UnionSchema).Types() Schemas
Type is a schema type. func (*ArraySchema).Type() Type func (*EnumSchema).Type() Type func (*FixedSchema).Type() Type func (*MapSchema).Type() Type func NamedSchema.Type() Type func (*NullSchema).Type() Type func (*PrimitiveSchema).Type() Type func (*RecordSchema).Type() Type func (*RefSchema).Type() Type func Schema.Type() Type func TypeConversionFuncs.Type() Type func TypeConverter.Type() Type func (*UnionSchema).Type() Type func NewPrimitiveSchema(t Type, l LogicalSchema, opts ...SchemaOption) *PrimitiveSchema func (*UnionSchema).Contains(typ Type) bool const Array const Boolean const Bytes const Double const Enum const Error const Fixed const Float const Int const Long const Map const Null const Record const Ref const String const Union
TypeConversionFuncs is a helper struct to reduce boilerplate in user code. Implements the TypeConverter interface. AvroLogicalType LogicalType AvroType Type DecoderTypeConversion func(in any, schema Schema) (any, error) EncoderTypeConversion func(in any, schema Schema) (any, error) DecodeTypeConvert runs the converter's decoder type conversion function if it's set. EncodeTypeConvert runs the converter's encoder type conversion function if it's set. LogicalType returns the Avro data type of the type converter. Type returns the Avro data type of the type converter. TypeConversionFuncs : TypeConverter
TypeConverter represents a data type converter. DecodeTypeConvert is the type conversion function called after decoding from Avro. EncodeTypeConvert is the type conversion function called before encoding to Avro. LogicalType returns the Avro logical data type of the type converter. Type returns the Avro data type of the type converter. TypeConversionFuncs func RegisterTypeConverters(convs ...TypeConverter) func API.RegisterTypeConverters(conv ...TypeConverter) func (*TypeConverters).RegisterTypeConverters(convs ...TypeConverter)
TypeConverters holds the user-provided type conversion functions. DecodeTypeConvert runs the decode type conversion function for the given value and schema. EncodeTypeConvert runs the encode type conversion function for the given value and schema. RegisterTypeConverters registers type converters for converting the data types during encoding and decoding. func NewTypeConverters() *TypeConverters
TypeResolver resolves types by name. Name gets the name for a type, or an error. Register registers names to their types for resolution. Type gets the type for a name, or an error. func NewTypeResolver() *TypeResolver
UnionConverter to handle Avro Union's in a type-safe way. FromAny payload decode into any of the mentioned types in the Union. ToAny from the Union struct
UnionSchema is an Avro union type schema. CacheFingerprint returns unique identity of the schema. Contains returns true if the union contains the given type. Fingerprint returns the SHA256 fingerprint of the schema. FingerprintUsing returns the fingerprint of the schema using the given algorithm or an error. Indices returns the index of the null and type schemas for a nullable schema. For non-nullable schemas 0 is returned for both. MarshalJSON marshals the schema to json. Nullable returns true if the union is nullable, otherwise false. String returns the canonical form of the schema. Type returns the type of the schema. Types returns the types of a union. *UnionSchema : Schema *UnionSchema : github.com/goccy/go-json.Marshaler *UnionSchema : encoding/json.Marshaler *UnionSchema : expvar.Var *UnionSchema : fmt.Stringer func NewUnionSchema(types []Schema, opts ...SchemaOption) (*UnionSchema, error) func (*Message).Errors() *UnionSchema func NewMessage(req *RecordSchema, resp Schema, errors *UnionSchema, oneWay bool, opts ...ProtocolOption) *Message
ValDecoder represents an internal value decoder. You should never use ValDecoder directly. ( ValDecoder) Decode(ptr unsafe.Pointer, r *Reader) func API.DecoderOf(schema Schema, typ reflect2.Type) ValDecoder
ValEncoder represents an internal value encoder. You should never use ValEncoder directly. ( ValEncoder) Encode(ptr unsafe.Pointer, w *Writer) func API.EncoderOf(schema Schema, typ reflect2.Type) ValEncoder
Writer is an Avro specific io.Writer. Error error Buffer gets the Writer buffer. Buffered returns the number of buffered bytes. Flush writes any buffered data to the underlying io.Writer. Reset resets the Writer with a new io.Writer attached. Write writes raw bytes to the Writer. WriteBlockCB writes a block using the callback. WriteBlockHeader writes a Block Header to the Writer. WriteBool writes a Bool to the Writer. WriteBytes writes Bytes to the Writer. WriteDouble writes a Double to the Writer. WriteFloat writes a Float to the Writer. WriteInt writes an Int to the Writer. WriteLong writes a Long to the Writer. WriteString reads a String to the Writer. WriteVal writes the Avro encoding of obj. *Writer : github.com/apache/thrift/lib/go/thrift.Flusher *Writer : github.com/miekg/dns.Writer *Writer : internal/bisect.Writer *Writer : io.Writer func NewWriter(out io.Writer, bufSize int, opts ...WriterFunc) *Writer func ValEncoder.Encode(ptr unsafe.Pointer, w *Writer)
WriterFunc is a function used to customize the Writer. func WithWriterConfig(cfg API) WriterFunc func NewWriter(out io.Writer, bufSize int, opts ...WriterFunc) *Writer
Package-Level Functions (total 46)
Marshal returns the Avro encoding of v.
MustParse parses a schema string, panicking if there is an error.
MustParseProtocol parses an Avro protocol, panicing if there is an error.
NewArraySchema creates an array schema instance.
NewDecimalLogicalSchema creates a new decimal logical schema instance.
NewDecoder returns a new decoder that reads from reader r using schema s.
NewDecoderForSchema returns a new decoder that reads from r using schema.
NewEncoder returns a new encoder that writes to w using schema s.
NewEncoderForSchema returns a new encoder that writes to w using schema.
NewEnumSchema creates a new enum schema instance.
NewErrorRecordSchema creates a new error record schema instance.
NewField creates a new field instance.
NewFixedSchema creates a new fixed schema instance.
NewMapSchema creates a map schema instance.
NewMessage creates a protocol message instance.
NewNullSchema creates a new NullSchema.
NewPrimitiveLogicalSchema creates a new primitive logical schema instance.
NewPrimitiveSchema creates a new PrimitiveSchema.
NewProtocol creates a protocol instance.
NewReader creates a new Reader.
NewRecordSchema creates a new record schema instance.
NewRefSchema creates a ref schema instance.
NewSchemaCompatibility creates a new schema compatibility instance.
NewTypeConverters creates a new type converter.
NewTypeResolver creates a new type resolver with all primitive types registered.
NewUnionSchema creates a union schema instance.
NewWriter creates a new Writer.
Parse parses a schema string.
ParseBytes parses a schema byte slice.
ParseBytesWithCache parses a schema byte slice using the given namespace and schema cache.
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.
ParseProtocol parses an Avro protocol.
ParseProtocolFile parses an Avro protocol from a file.
ParseWithCache parses a schema string using the given namespace and schema cache.
Register registers names to their types for resolution. All primitive types are pre-registered.
RegisterTypeConverters registers type converters for encoding and decoding the data type specified in the converter.
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.
WithAliases sets the aliases on a schema.
WithDefault sets the default on a schema.
WithDoc sets the doc on a schema.
WithOrder sets the order on a schema.
WithProps sets the properties on a schema.
WithProtoDoc sets the doc on a protocol.
WithProtoProps sets the properties on a protocol.
WithReaderConfig specifies the configuration to use with a reader.
WithWriterConfig specifies the configuration to use with a writer.
Package-Level Variables (total 4)
DefaultConfig is the default API.
DefaultSchemaCache is the default cache for schemas.
NoDefault is used when no default exists for a field.
SkipNameValidation sets whether to skip name validation. Avro spec incurs a strict naming convention for names and aliases, however official Avro tools do not follow that More info: https://lists.apache.org/thread/39v98os6wdpyr6w31xdkz0yzol51fsrr https://github.com/apache/avro/pull/1995
Package-Level Constants (total 35)
Schema type constants.
Field orders.
Schema type constants.
Schema type constants.
Fingerprint type constants.
Fingerprint type constants.
Schema logical type constants.
Schema logical type constants.
Field orders.
Schema type constants.
Schema logical type constants.
Schema type constants.
Schema type constants.
Action type constants.
Action type constants.
Schema type constants.
Schema type constants.
Field orders.
Schema type constants.
Schema logical type constants.
Schema logical type constants.
Schema type constants.
Schema type constants.
Fingerprint type constants.
Schema type constants.
Schema type constants.
Schema type constants.
Fingerprint type constants.
Schema type constants.
Schema logical type constants.
Schema logical type constants.
Schema logical type constants.
Schema logical type constants.
Schema type constants.
Schema logical type constants.