Documentation ¶
Index ¶
- Constants
- Variables
- func LoadSchemas(path string) map[string]Schema
- type ArraySchema
- type AvroRecord
- type BinaryDecoder
- func (this *BinaryDecoder) ArrayNext() (int64, error)
- func (this *BinaryDecoder) MapNext() (int64, error)
- func (this *BinaryDecoder) ReadArrayStart() (int64, error)
- func (this *BinaryDecoder) ReadBoolean() (bool, error)
- func (this *BinaryDecoder) ReadBytes() ([]byte, error)
- func (this *BinaryDecoder) ReadDouble() (float64, error)
- func (this *BinaryDecoder) ReadEnum() (int32, error)
- func (this *BinaryDecoder) ReadFixed(bytes []byte) error
- func (this *BinaryDecoder) ReadFixedWithBounds(bytes []byte, start int, length int) error
- func (this *BinaryDecoder) ReadFloat() (float32, error)
- func (this *BinaryDecoder) ReadInt() (int32, error)
- func (this *BinaryDecoder) ReadLong() (int64, error)
- func (this *BinaryDecoder) ReadMapStart() (int64, error)
- func (this *BinaryDecoder) ReadNull() (interface{}, error)
- func (this *BinaryDecoder) ReadString() (string, error)
- func (this *BinaryDecoder) Seek(pos int64)
- func (this *BinaryDecoder) SetBlock(block *DataBlock)
- func (this *BinaryDecoder) Tell() int64
- type BinaryEncoder
- func (this *BinaryEncoder) WriteArrayNext(count int64)
- func (this *BinaryEncoder) WriteArrayStart(count int64)
- func (this *BinaryEncoder) WriteBoolean(x bool)
- func (this *BinaryEncoder) WriteBytes(x []byte)
- func (this *BinaryEncoder) WriteDouble(x float64)
- func (this *BinaryEncoder) WriteFloat(x float32)
- func (this *BinaryEncoder) WriteInt(x int32)
- func (this *BinaryEncoder) WriteLong(x int64)
- func (this *BinaryEncoder) WriteMapNext(count int64)
- func (this *BinaryEncoder) WriteMapStart(count int64)
- func (this *BinaryEncoder) WriteNull(_ interface{})
- func (this *BinaryEncoder) WriteRaw(x []byte)
- func (this *BinaryEncoder) WriteString(x string)
- type BooleanSchema
- type BytesSchema
- type CodeGenerator
- type DataBlock
- type DataFileReader
- type DatumReader
- type DatumWriter
- type Decoder
- type DoubleSchema
- type Encoder
- type EnumSchema
- type FixedSchema
- type FloatSchema
- type GenericDatumReader
- type GenericDatumWriter
- type GenericEnum
- type GenericRecord
- type IntSchema
- type LongSchema
- type MapSchema
- type NullSchema
- type Reader
- type RecordSchema
- type RecursiveSchema
- func (this *RecursiveSchema) GetName() string
- func (this *RecursiveSchema) MarshalJSON() ([]byte, error)
- func (*RecursiveSchema) Prop(key string) (string, bool)
- func (this *RecursiveSchema) String() string
- func (*RecursiveSchema) Type() int
- func (this *RecursiveSchema) Validate(v reflect.Value) bool
- type Schema
- type SchemaField
- type SpecificDatumReader
- type SpecificDatumWriter
- type StringSchema
- type UnionSchema
- func (*UnionSchema) GetName() string
- func (this *UnionSchema) GetType(v reflect.Value) int
- func (this *UnionSchema) MarshalJSON() ([]byte, error)
- func (*UnionSchema) Prop(key string) (string, bool)
- func (this *UnionSchema) String() string
- func (*UnionSchema) Type() int
- func (this *UnionSchema) Validate(v reflect.Value) bool
- type Writer
Constants ¶
const ( // Record schema type constant Record int = iota // Enum schema type constant Enum // Array schema type constant Array // Map schema type constant Map // Union schema type constant Union // Fixed schema type constant Fixed // String schema type constant String // Bytes schema type constant Bytes // Int schema type constant Int // Long schema type constant Long // Float schema type constant Float // Double schema type constant Double // Boolean schema type constant Boolean // Null schema type constant Null // Recursive schema type constant. Recursive is an artificial type that means a Record schema without its definition // that should be looked up in some registry. Recursive )
Variables ¶
var BlockNotFinished = errors.New("Block read is unfinished")
Happens when trying to read next block without finishing the previous one.
var EOF = errors.New("End of file reached")
Signals that an end of file or stream has been reached unexpectedly.
var IntOverflow = errors.New("Overflowed an int value")
Happens when the given value to decode overflows maximum int32 value.
var InvalidBool = errors.New("Invalid bool value")
Happens when given value to decode as bool is neither 0x00 nor 0x01.
var InvalidFixedSize = errors.New("Invalid Fixed type size")
Happens when avro schema contains invalid value for fixed size.
var InvalidSchema = errors.New("Invalid schema")
Happens when avro schema is unparsable or is invalid in any other way.
var InvalidStringLength = errors.New("Invalid string length")
Happens when given value to decode as string has either negative or undecodable length.
var InvalidSync = errors.New("Invalid sync")
Happens when file header's sync and block's sync do not match - indicates corrupted data.
var InvalidValueType = errors.New("Invalid array or map value type")
Happens when avro schema contains invalid value for map value type or array item type.
var LongOverflow = errors.New("Overflowed a long value")
Happens when the given value to decode overflows maximum int64 value.
var NegativeBytesLength = errors.New("Negative bytes length")
Happens when given value to decode as bytes has negative length.
var NestedUnionsNotAllowed = errors.New("Nested unions are not allowed")
Happens when avro schema contains a union within union.
var NotAvroFile = errors.New("Not an Avro data file")
Indicates the given file to decode does not correspond to Avro data file format.
var SchemaNotSet = errors.New("Schema not set")
Happens when a datum reader has no set schema.
Functions ¶
func LoadSchemas ¶
Loads and parses a schema file or directory. Directory names MUST end with "/"
Types ¶
type ArraySchema ¶
ArraySchema implements Schema and represents Avro array type.
func (*ArraySchema) GetName ¶
func (*ArraySchema) GetName() string
Returns a type name for this ArraySchema.
func (*ArraySchema) MarshalJSON ¶
func (this *ArraySchema) MarshalJSON() ([]byte, error)
func (*ArraySchema) Prop ¶
func (this *ArraySchema) Prop(key string) (string, bool)
Gets a custom non-reserved string property from this schema and a bool representing if it exists.
func (*ArraySchema) String ¶
func (this *ArraySchema) String() string
Returns a JSON representation of ArraySchema.
func (*ArraySchema) Type ¶
func (*ArraySchema) Type() int
Returns a type constant for this ArraySchema.
type AvroRecord ¶
type AvroRecord interface {
Schema() Schema
}
type BinaryDecoder ¶
type BinaryDecoder struct {
// contains filtered or unexported fields
}
BinaryDecoder implements Decoder and provides low-level support for deserializing Avro values.
func NewBinaryDecoder ¶
func NewBinaryDecoder(buf []byte) *BinaryDecoder
Creates a new BinaryDecoder to read from a given buffer.
func (*BinaryDecoder) ArrayNext ¶
func (this *BinaryDecoder) ArrayNext() (int64, error)
Processes the next block of an array and returns the number of items in the block. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) MapNext ¶
func (this *BinaryDecoder) MapNext() (int64, error)
Processes the next block of map entries and returns the number of items in the block. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadArrayStart ¶
func (this *BinaryDecoder) ReadArrayStart() (int64, error)
Reads and returns the size of the first block of an array. If call to this return non-zero, then the caller should read the indicated number of items and then call ArrayNext() to find out the number of items in the next block. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadBoolean ¶
func (this *BinaryDecoder) ReadBoolean() (bool, error)
Reads a boolean value. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadBytes ¶
func (this *BinaryDecoder) ReadBytes() ([]byte, error)
Reads a bytes value. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadDouble ¶
func (this *BinaryDecoder) ReadDouble() (float64, error)
Reads a double value. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadEnum ¶
func (this *BinaryDecoder) ReadEnum() (int32, error)
Reads an enum value (which is an Avro int value). Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadFixed ¶
func (this *BinaryDecoder) ReadFixed(bytes []byte) error
Reads fixed sized binary object into the provided buffer. Returns an error if it occurs.
func (*BinaryDecoder) ReadFixedWithBounds ¶
func (this *BinaryDecoder) ReadFixedWithBounds(bytes []byte, start int, length int) error
Reads fixed sized binary object into the provided buffer. The second parameter is the position where the data needs to be written, the third is the size of binary object. Returns an error if it occurs.
func (*BinaryDecoder) ReadFloat ¶
func (this *BinaryDecoder) ReadFloat() (float32, error)
Reads a float value. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadInt ¶
func (this *BinaryDecoder) ReadInt() (int32, error)
Reads an int value. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadLong ¶
func (this *BinaryDecoder) ReadLong() (int64, error)
Reads a long value. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadMapStart ¶
func (this *BinaryDecoder) ReadMapStart() (int64, error)
Reads and returns the size of the first block of map entries. If call to this return non-zero, then the caller should read the indicated number of items and then call MapNext() to find out the number of items in the next block. Usage is similar to ReadArrayStart(). Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadNull ¶
func (this *BinaryDecoder) ReadNull() (interface{}, error)
Reads a null value. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) ReadString ¶
func (this *BinaryDecoder) ReadString() (string, error)
Reads a string value. Returns a decoded value and an error if it occurs.
func (*BinaryDecoder) Seek ¶
func (this *BinaryDecoder) Seek(pos int64)
Seek sets the reading position of this Decoder to a given value allowing to skip items etc.
func (*BinaryDecoder) SetBlock ¶
func (this *BinaryDecoder) SetBlock(block *DataBlock)
SetBlock is used for Avro Object Container Files where the data is split in blocks and sets a data block for this decoder and sets the position to the start of this block.
func (*BinaryDecoder) Tell ¶
func (this *BinaryDecoder) Tell() int64
Tell returns the current reading position of this Decoder.
type BinaryEncoder ¶
type BinaryEncoder struct {
// contains filtered or unexported fields
}
BinaryEncoder implements Encoder and provides low-level support for serializing Avro values.
func NewBinaryEncoder ¶
func NewBinaryEncoder(buffer io.Writer) *BinaryEncoder
Creates a new BinaryEncoder that will write to a given io.Writer.
func (*BinaryEncoder) WriteArrayNext ¶
func (this *BinaryEncoder) WriteArrayNext(count int64)
WriteArrayNext should be called after finishing writing an array block either passing it the number of items in next block or 0 indicating the end of array.
func (*BinaryEncoder) WriteArrayStart ¶
func (this *BinaryEncoder) WriteArrayStart(count int64)
WriteArrayNext should be called after finishing writing an array block either passing it the number of items in next block or 0 indicating the end of array.
func (*BinaryEncoder) WriteBoolean ¶
func (this *BinaryEncoder) WriteBoolean(x bool)
Writes a boolean value.
func (*BinaryEncoder) WriteBytes ¶
func (this *BinaryEncoder) WriteBytes(x []byte)
Writes a bytes value.
func (*BinaryEncoder) WriteDouble ¶
func (this *BinaryEncoder) WriteDouble(x float64)
Writes a double value.
func (*BinaryEncoder) WriteFloat ¶
func (this *BinaryEncoder) WriteFloat(x float32)
Writes a float value.
func (*BinaryEncoder) WriteLong ¶
func (this *BinaryEncoder) WriteLong(x int64)
Writes a long value.
func (*BinaryEncoder) WriteMapNext ¶
func (this *BinaryEncoder) WriteMapNext(count int64)
WriteMapNext should be called after finishing writing a map block either passing it the number of items in next block or 0 indicating the end of map.
func (*BinaryEncoder) WriteMapStart ¶
func (this *BinaryEncoder) WriteMapStart(count int64)
WriteMapStart should be called when starting to serialize a map providing it with a number of items in map block.
func (*BinaryEncoder) WriteNull ¶
func (this *BinaryEncoder) WriteNull(_ interface{})
Writes a null value. Doesn't actually do anything in this implementation.
func (*BinaryEncoder) WriteRaw ¶
func (this *BinaryEncoder) WriteRaw(x []byte)
Writes raw bytes to this Encoder.
func (*BinaryEncoder) WriteString ¶
func (this *BinaryEncoder) WriteString(x string)
Writes a string value.
type BooleanSchema ¶
type BooleanSchema struct{}
BooleanSchema implements Schema and represents Avro boolean type.
func (*BooleanSchema) GetName ¶
func (*BooleanSchema) GetName() string
Returns a type name for this BooleanSchema.
func (*BooleanSchema) MarshalJSON ¶
func (this *BooleanSchema) MarshalJSON() ([]byte, error)
func (*BooleanSchema) Prop ¶
func (*BooleanSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for BooleanSchema.
func (*BooleanSchema) String ¶
func (*BooleanSchema) String() string
Returns a JSON representation of BooleanSchema.
func (*BooleanSchema) Type ¶
func (*BooleanSchema) Type() int
Returns a type constant for this BooleanSchema.
type BytesSchema ¶
type BytesSchema struct{}
BytesSchema implements Schema and represents Avro bytes type.
func (*BytesSchema) GetName ¶
func (*BytesSchema) GetName() string
Returns a type name for this BytesSchema.
func (*BytesSchema) MarshalJSON ¶
func (this *BytesSchema) MarshalJSON() ([]byte, error)
func (*BytesSchema) Prop ¶
func (*BytesSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for BytesSchema.
func (*BytesSchema) String ¶
func (*BytesSchema) String() string
Returns a JSON representation of BytesSchema.
func (*BytesSchema) Type ¶
func (*BytesSchema) Type() int
Returns a type constant for this BytesSchema.
type CodeGenerator ¶
type CodeGenerator struct {
// contains filtered or unexported fields
}
CodeGenerator is a code generation tool for structs from given Avro schemas.
func NewCodeGenerator ¶
func NewCodeGenerator(schemas []string) *CodeGenerator
Creates a new CodeGenerator for given Avro schemas.
func (*CodeGenerator) Generate ¶
func (this *CodeGenerator) Generate() (string, error)
Generates source code for Avro schemas specified on creation. The ouput is Go formatted source code that contains struct definitions for all given schemas. May return an error if code generation fails, e.g. due to unparsable schema.
type DataBlock ¶
type DataBlock struct { // Actual data Data []byte // Number of entries encoded in Data. NumEntries int64 // Size of data buffer in bytes. BlockSize int // Number of unread entries in this DataBlock. BlockRemaining int64 }
DataBlock is a structure that holds a certain amount of entries and the actual buffer to read from.
type DataFileReader ¶
type DataFileReader struct {
// contains filtered or unexported fields
}
DataFileReader is a reader for Avro Object Container Files. More here: https://avro.apache.org/docs/current/spec.html#Object+Container+Files
func NewDataFileReader ¶
func NewDataFileReader(filename string, datumReader DatumReader) (*DataFileReader, error)
Creates a new DataFileReader for a given file and using the given DatumReader to read the data from that file. May return an error if the file contains invalid data or is just missing.
func (*DataFileReader) Next ¶
func (this *DataFileReader) Next(v interface{}) (bool, error)
Reads the next value from file and fills the given value with data. First return value indicates whether the read was successful. Second return value indicates whether there was an error while reading data. Returns (false, nil) when no more data left to read.
func (*DataFileReader) NextBlock ¶
func (this *DataFileReader) NextBlock() error
Tells this DataFileReader to skip current block and move to next one. May return an error if the block is malformed or no more blocks left to read.
func (*DataFileReader) Seek ¶
func (this *DataFileReader) Seek(pos int64)
Switches the reading position in this DataFileReader to a provided value.
type DatumReader ¶
type DatumReader interface { // Reads a single structured entry using this DatumReader according to provided Schema. // Accepts a value to fill with data and a Decoder to read from. Given value MUST be of pointer type. // May return an error indicating a read failure. Read(interface{}, Decoder) error // Sets the schema for this DatumReader to know the data structure. // Note that it must be called before calling Read. SetSchema(Schema) }
DatumReader is an interface that is responsible for reading structured data according to schema from a decoder
type DatumWriter ¶
type DatumWriter interface { // Write writes a single entry using this DatumWriter according to provided Schema. // Accepts a value to write and Encoder to write to. // May return an error indicating a write failure. Write(interface{}, Encoder) error // Sets the schema for this DatumWriter to know the data structure. // Note that it must be called before calling Write. SetSchema(Schema) }
DatumWriter is an interface that is responsible for writing structured data according to schema to an encoder.
type Decoder ¶
type Decoder interface { // Reads a null value. Returns a decoded value and an error if it occurs. ReadNull() (interface{}, error) // Reads a boolean value. Returns a decoded value and an error if it occurs. ReadBoolean() (bool, error) // Reads an in value. Returns a decoded value and an error if it occurs. ReadInt() (int32, error) // Reads a long value. Returns a decoded value and an error if it occurs. ReadLong() (int64, error) // Reads a float value. Returns a decoded value and an error if it occurs. ReadFloat() (float32, error) // Reads a double value. Returns a decoded value and an error if it occurs. ReadDouble() (float64, error) // Reads a bytes value. Returns a decoded value and an error if it occurs. ReadBytes() ([]byte, error) // Reads a string value. Returns a decoded value and an error if it occurs. ReadString() (string, error) // Reads an enum value (which is an Avro int value). Returns a decoded value and an error if it occurs. ReadEnum() (int32, error) // Reads and returns the size of the first block of an array. If call to this return non-zero, then the caller // should read the indicated number of items and then call ArrayNext() to find out the number of items in the // next block. Returns a decoded value and an error if it occurs. ReadArrayStart() (int64, error) // Processes the next block of an array and returns the number of items in the block. // Returns a decoded value and an error if it occurs. ArrayNext() (int64, error) // Reads and returns the size of the first block of map entries. If call to this return non-zero, then the caller // should read the indicated number of items and then call MapNext() to find out the number of items in the // next block. Usage is similar to ReadArrayStart(). Returns a decoded value and an error if it occurs. ReadMapStart() (int64, error) // Processes the next block of map entries and returns the number of items in the block. // Returns a decoded value and an error if it occurs. MapNext() (int64, error) // Reads fixed sized binary object into the provided buffer. // Returns an error if it occurs. ReadFixed([]byte) error // Reads fixed sized binary object into the provided buffer. // The second parameter is the position where the data needs to be written, the third is the size of binary object. // Returns an error if it occurs. ReadFixedWithBounds([]byte, int, int) error // SetBlock is used for Avro Object Container Files where the data is split in blocks and sets a data block // for this decoder and sets the position to the start of this block. SetBlock(*DataBlock) // Seek sets the reading position of this Decoder to a given value allowing to skip items etc. Seek(int64) // Tell returns the current reading position of this Decoder. Tell() int64 }
Decoder is an interface that provides low-level support for deserializing Avro values.
type DoubleSchema ¶
type DoubleSchema struct{}
DoubleSchema implements Schema and represents Avro double type.
func (*DoubleSchema) GetName ¶
func (*DoubleSchema) GetName() string
Returns a type name for this DoubleSchema.
func (*DoubleSchema) MarshalJSON ¶
func (this *DoubleSchema) MarshalJSON() ([]byte, error)
func (*DoubleSchema) Prop ¶
func (*DoubleSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for DoubleSchema.
func (*DoubleSchema) String ¶
func (*DoubleSchema) String() string
Returns a JSON representation of DoubleSchema.
func (*DoubleSchema) Type ¶
func (*DoubleSchema) Type() int
Returns a type constant for this DoubleSchema.
type Encoder ¶
type Encoder interface { // Writes a null value. Doesn't actually do anything but may advance the state of Encoder implementation if it // is stateful. WriteNull(interface{}) // Writes a boolean value. WriteBoolean(bool) // Writes an int value. WriteInt(int32) // Writes a long value. WriteLong(int64) // Writes a float value. WriteFloat(float32) // Writes a double value. WriteDouble(float64) // Writes a bytes value. WriteBytes([]byte) // Writes a string value. WriteString(string) // WriteArrayStart should be called when starting to serialize an array providing it with a number of items in // array block. WriteArrayStart(int64) // WriteArrayNext should be called after finishing writing an array block either passing it the number of items in // next block or 0 indicating the end of array. WriteArrayNext(int64) // WriteMapStart should be called when starting to serialize a map providing it with a number of items in // map block. WriteMapStart(int64) // WriteMapNext should be called after finishing writing a map block either passing it the number of items in // next block or 0 indicating the end of map. WriteMapNext(int64) // Writes raw bytes to this Encoder. WriteRaw([]byte) }
Encoder is an interface that provides low-level support for serializing Avro values.
type EnumSchema ¶
type EnumSchema struct { Name string Namespace string Aliases []string Doc string Symbols []string Properties map[string]string }
EnumSchema implements Schema and represents Avro enum type.
func (*EnumSchema) GetName ¶
func (this *EnumSchema) GetName() string
Returns an enum name for this EnumSchema.
func (*EnumSchema) MarshalJSON ¶
func (this *EnumSchema) MarshalJSON() ([]byte, error)
func (*EnumSchema) Prop ¶
func (this *EnumSchema) Prop(key string) (string, bool)
Gets a custom non-reserved string property from this schema and a bool representing if it exists.
func (*EnumSchema) String ¶
func (this *EnumSchema) String() string
Returns a JSON representation of EnumSchema.
func (*EnumSchema) Type ¶
func (*EnumSchema) Type() int
Returns a type constant for this EnumSchema.
type FixedSchema ¶
FixedSchema implements Schema and represents Avro fixed type.
func (*FixedSchema) GetName ¶
func (this *FixedSchema) GetName() string
Returns a fixed name for this FixedSchema.
func (*FixedSchema) MarshalJSON ¶
func (this *FixedSchema) MarshalJSON() ([]byte, error)
func (*FixedSchema) Prop ¶
func (this *FixedSchema) Prop(key string) (string, bool)
Gets a custom non-reserved string property from this schema and a bool representing if it exists.
func (*FixedSchema) String ¶
func (this *FixedSchema) String() string
Returns a JSON representation of FixedSchema.
func (*FixedSchema) Type ¶
func (*FixedSchema) Type() int
Returns a type constant for this FixedSchema.
type FloatSchema ¶
type FloatSchema struct{}
FloatSchema implements Schema and represents Avro float type.
func (*FloatSchema) GetName ¶
func (*FloatSchema) GetName() string
Returns a type name for this FloatSchema.
func (*FloatSchema) MarshalJSON ¶
func (this *FloatSchema) MarshalJSON() ([]byte, error)
func (*FloatSchema) Prop ¶
func (*FloatSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for FloatSchema.
func (*FloatSchema) String ¶
func (*FloatSchema) String() string
Returns a JSON representation of FloatSchema.
func (*FloatSchema) Type ¶
func (*FloatSchema) Type() int
Returns a type constant for this FloatSchema.
type GenericDatumReader ¶
type GenericDatumReader struct {
// contains filtered or unexported fields
}
GenericDatumReader implements DatumReader and is used for filling GenericRecords or other Avro supported types (full list is: interface{}, bool, int32, int64, float32, float64, string, slices of any type, maps with string keys and any values, GenericEnums) with data. Each value passed to Read is expected to be a pointer.
func NewGenericDatumReader ¶
func NewGenericDatumReader() *GenericDatumReader
Creates a new GenericDatumReader.
func (*GenericDatumReader) Read ¶
func (this *GenericDatumReader) Read(v interface{}, dec Decoder) error
Reads a single entry using this GenericDatumReader. Accepts a value to fill with data and a Decoder to read from. Given value MUST be of pointer type. May return an error indicating a read failure.
func (*GenericDatumReader) SetSchema ¶
func (this *GenericDatumReader) SetSchema(schema Schema)
Sets the schema for this GenericDatumReader to know the data structure. Note that it must be called before calling Read.
type GenericDatumWriter ¶
type GenericDatumWriter struct {
// contains filtered or unexported fields
}
GenericDatumWriter implements DatumWriter and is used for writing GenericRecords or other Avro supported types (full list is: interface{}, bool, int32, int64, float32, float64, string, slices of any type, maps with string keys and any values, GenericEnums) to a given Encoder.
func NewGenericDatumWriter ¶
func NewGenericDatumWriter() *GenericDatumWriter
Creates a new GenericDatumWriter.
func (*GenericDatumWriter) SetSchema ¶
func (this *GenericDatumWriter) SetSchema(schema Schema)
Sets the schema for this GenericDatumWriter to know the data structure. Note that it must be called before calling Write.
func (*GenericDatumWriter) Write ¶
func (this *GenericDatumWriter) Write(obj interface{}, enc Encoder) error
Write writes a single entry using this GenericDatumWriter according to provided Schema. Accepts a value to write and Encoder to write to. May return an error indicating a write failure.
type GenericEnum ¶
type GenericEnum struct { // Avro enum symbols. Symbols []string // contains filtered or unexported fields }
Generic Avro enum representation. This is still subject to change and may be rethought.
func NewGenericEnum ¶
func NewGenericEnum(symbols []string) *GenericEnum
Returns a new GenericEnum that uses provided enum symbols.
func (*GenericEnum) Get ¶
func (this *GenericEnum) Get() string
Gets the string value for this enum (e.g. symbol).
func (*GenericEnum) GetIndex ¶
func (this *GenericEnum) GetIndex() int32
Gets the numeric value for this enum.
func (*GenericEnum) Set ¶
func (this *GenericEnum) Set(symbol string)
Sets the string value for this enum (e.g. symbol). Panics if the given symbol does not exist in this enum.
func (*GenericEnum) SetIndex ¶
func (this *GenericEnum) SetIndex(index int32)
Sets the numeric value for this enum.
type GenericRecord ¶
type GenericRecord struct {
// contains filtered or unexported fields
}
GenericRecord is a generic instance of a record schema. Fields are accessible by their name.
func NewGenericRecord ¶
func NewGenericRecord(schema Schema) *GenericRecord
Creates a new GenericRecord.
func (*GenericRecord) Get ¶
func (this *GenericRecord) Get(name string) interface{}
Gets a value by its name.
func (*GenericRecord) Schema ¶
func (this *GenericRecord) Schema() Schema
Returns a schema for this GenericRecord.
func (*GenericRecord) Set ¶
func (this *GenericRecord) Set(name string, value interface{})
Sets a value for a given name.
type IntSchema ¶
type IntSchema struct{}
IntSchema implements Schema and represents Avro int type.
func (*IntSchema) MarshalJSON ¶
type LongSchema ¶
type LongSchema struct{}
LongSchema implements Schema and represents Avro long type.
func (*LongSchema) GetName ¶
func (*LongSchema) GetName() string
Returns a type name for this LongSchema.
func (*LongSchema) MarshalJSON ¶
func (this *LongSchema) MarshalJSON() ([]byte, error)
func (*LongSchema) Prop ¶
func (*LongSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for LongSchema.
func (*LongSchema) String ¶
func (*LongSchema) String() string
Returns a JSON representation of LongSchema.
func (*LongSchema) Type ¶
func (*LongSchema) Type() int
Returns a type constant for this LongSchema.
type MapSchema ¶
MapSchema implements Schema and represents Avro map type.
func (*MapSchema) MarshalJSON ¶
func (*MapSchema) Prop ¶
Gets a custom non-reserved string property from this schema and a bool representing if it exists.
type NullSchema ¶
type NullSchema struct{}
NullSchema implements Schema and represents Avro null type.
func (*NullSchema) GetName ¶
func (*NullSchema) GetName() string
Returns a type name for this NullSchema.
func (*NullSchema) MarshalJSON ¶
func (this *NullSchema) MarshalJSON() ([]byte, error)
func (*NullSchema) Prop ¶
func (*NullSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for NullSchema.
func (*NullSchema) String ¶
func (*NullSchema) String() string
Returns a JSON representation of NullSchema.
func (*NullSchema) Type ¶
func (*NullSchema) Type() int
Returns a type constant for this NullSchema.
type Reader ¶
Reader is an interface that may be implemented to avoid using runtime reflection during deserialization. Implementing it is optional and may be used as an optimization. Falls back to using reflection if not implemented.
type RecordSchema ¶
type RecordSchema struct { Name string `json:"name,omitempty"` Namespace string `json:"namespace,omitempty"` Doc string `json:"doc,omitempty"` Aliases []string `json:"aliases,omitempty"` Properties map[string]string Fields []*SchemaField `json:"fields"` }
RecordSchema implements Schema and represents Avro record type.
func (*RecordSchema) GetName ¶
func (this *RecordSchema) GetName() string
Returns a record name for this RecordSchema.
func (*RecordSchema) MarshalJSON ¶
func (this *RecordSchema) MarshalJSON() ([]byte, error)
func (*RecordSchema) Prop ¶
func (this *RecordSchema) Prop(key string) (string, bool)
Gets a custom non-reserved string property from this schema and a bool representing if it exists.
func (*RecordSchema) String ¶
func (this *RecordSchema) String() string
Returns a JSON representation of RecordSchema.
func (*RecordSchema) Type ¶
func (*RecordSchema) Type() int
Returns a type constant for this RecordSchema.
type RecursiveSchema ¶
type RecursiveSchema struct {
Actual *RecordSchema
}
RecursiveSchema implements Schema and represents Avro record type without a definition (e.g. that should be looked up).
func (*RecursiveSchema) GetName ¶
func (this *RecursiveSchema) GetName() string
Returns a record name for enclosed RecordSchema.
func (*RecursiveSchema) MarshalJSON ¶
func (this *RecursiveSchema) MarshalJSON() ([]byte, error)
func (*RecursiveSchema) Prop ¶
func (*RecursiveSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for RecursiveSchema.
func (*RecursiveSchema) String ¶
func (this *RecursiveSchema) String() string
Returns a JSON representation of RecursiveSchema.
func (*RecursiveSchema) Type ¶
func (*RecursiveSchema) Type() int
Returns a type constant for this RecursiveSchema.
type Schema ¶
type Schema interface { // Returns an integer constant representing this schema type. Type() int // If this is a record, enum or fixed, returns its name, otherwise the name of the primitive type. GetName() string // Gets a custom non-reserved string property from this schema and a bool representing if it exists. Prop(key string) (string, bool) // Converts this schema to its JSON representation. String() string // Checks whether the given value is writeable to this schema. Validate(v reflect.Value) bool }
Schema is an interface representing a single Avro schema (both primitive and complex).
func MustParseSchema ¶
MustParseSchema is like ParseSchema, but panics if the given schema cannot be parsed.
func ParseSchema ¶
Parses a given schema without provided schemas to reuse. Equivalent to call ParseSchemaWithResistry(rawSchema, make(map[string]Schema)) May return an error if schema is not parsable or has insufficient information about any type.
func ParseSchemaFile ¶
Parses a given file. May return an error if schema is not parsable or file does not exist.
func ParseSchemaWithRegistry ¶
Parses a given schema using the provided registry for type lookup. Registry will be filled up during parsing. May return an error if schema is not parsable or has insufficient information about any type.
type SchemaField ¶
type SchemaField struct { Name string `json:"name,omitempty"` Doc string `json:"doc,omitempty"` Default interface{} `json:"default"` Type Schema `json:"type,omitempty"` }
SchemaField represents a schema field for Avro record.
func (*SchemaField) MarshalJSON ¶
func (this *SchemaField) MarshalJSON() ([]byte, error)
func (*SchemaField) String ¶
func (this *SchemaField) String() string
Returns a JSON representation of SchemaField.
type SpecificDatumReader ¶
type SpecificDatumReader struct {
// contains filtered or unexported fields
}
SpecificDatumReader implements DatumReader and is used for filling Go structs with data. Each value passed to Read is expected to be a pointer.
func NewSpecificDatumReader ¶
func NewSpecificDatumReader() *SpecificDatumReader
Creates a new SpecificDatumReader.
func (*SpecificDatumReader) Read ¶
func (this *SpecificDatumReader) Read(v interface{}, dec Decoder) error
Reads a single structured entry using this SpecificDatumReader. Accepts a Go struct with exported fields to fill with data and a Decoder to read from. Given value MUST be of pointer type. Field names should match field names in Avro schema but be exported (e.g. "some_value" in Avro schema is expected to be Some_value in struct) or you may provide Go struct tags to explicitly show how to map fields (e.g. if you want to map "some_value" field of type int to SomeValue in Go struct you should define your struct field as follows: SomeValue int32 `avro:"some_field"`). May return an error indicating a read failure.
func (*SpecificDatumReader) SetSchema ¶
func (this *SpecificDatumReader) SetSchema(schema Schema)
Sets the schema for this SpecificDatumReader to know the data structure. Note that it must be called before calling Read.
type SpecificDatumWriter ¶
type SpecificDatumWriter struct {
// contains filtered or unexported fields
}
SpecificDatumWriter implements DatumWriter and is used for writing Go structs in Avro format.
func NewSpecificDatumWriter ¶
func NewSpecificDatumWriter() *SpecificDatumWriter
Creates a new SpecificDatumWriter.
func (*SpecificDatumWriter) SetSchema ¶
func (this *SpecificDatumWriter) SetSchema(schema Schema)
Sets the schema for this SpecificDatumWriter to know the data structure. Note that it must be called before calling Write.
func (*SpecificDatumWriter) Write ¶
func (this *SpecificDatumWriter) Write(obj interface{}, enc Encoder) error
Write writes a single Go struct using this SpecificDatumWriter according to provided Schema. Accepts a value to write and Encoder to write to. Field names should match field names in Avro schema but be exported (e.g. "some_value" in Avro schema is expected to be Some_value in struct) or you may provide Go struct tags to explicitly show how to map fields (e.g. if you want to map "some_value" field of type int to SomeValue in Go struct you should define your struct field as follows: SomeValue int32 `avro:"some_field"`). May return an error indicating a write failure.
type StringSchema ¶
type StringSchema struct{}
StringSchema implements Schema and represents Avro string type.
func (*StringSchema) GetName ¶
func (*StringSchema) GetName() string
Returns a type name for this StringSchema.
func (*StringSchema) MarshalJSON ¶
func (this *StringSchema) MarshalJSON() ([]byte, error)
func (*StringSchema) Prop ¶
func (*StringSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for StringSchema.
func (*StringSchema) String ¶
func (*StringSchema) String() string
Returns a JSON representation of StringSchema.
func (*StringSchema) Type ¶
func (*StringSchema) Type() int
Returns a type constant for this StringSchema.
type UnionSchema ¶
type UnionSchema struct {
Types []Schema
}
UnionSchema implements Schema and represents Avro union type.
func (*UnionSchema) GetName ¶
func (*UnionSchema) GetName() string
Returns a type name for this UnionSchema.
func (*UnionSchema) MarshalJSON ¶
func (this *UnionSchema) MarshalJSON() ([]byte, error)
func (*UnionSchema) Prop ¶
func (*UnionSchema) Prop(key string) (string, bool)
Doesn't return anything valuable for UnionSchema.
func (*UnionSchema) String ¶
func (this *UnionSchema) String() string
Returns a JSON representation of UnionSchema.
func (*UnionSchema) Type ¶
func (*UnionSchema) Type() int
Returns a type constant for this UnionSchema.