avro

package
v0.0.0-...-c4b8a4c Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2015 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

README

Apache Avro for Golang

Build Status

Please note that this project is still an early alpha and is subject to change.

Installation is as easy as follows:

go get github.com/stealthly/go-avro

Some usage examples are located in examples folder:

Documentation

Index

Constants

View Source
const (
	Record int = iota
	Enum
	Array
	Map
	Union
	Fixed
	String
	Bytes
	Int
	Long
	Float
	Double
	Boolean
	Null
)

Variables

View Source
var BlockNotFinished = errors.New("Block read is unfinished")

happens when trying to read next block without finishing the previous one

View Source
var CODEC_KEY = "avro.codec"
View Source
var EOF = errors.New("End of file reached")

signals that an end of file or stream has been reached unexpectedly

View Source
var IntOverflow = errors.New("Overflowed an int value")

happens when the given value to decode overflows maximum int32 value

View Source
var InvalidBool = errors.New("Invalid bool value")

happens when given value to decode as bool is neither 0x00 nor 0x01

View Source
var InvalidFixedSize = errors.New("Invalid Fixed type size")

happens when avro schema contains invalid value for fixed size

View Source
var InvalidSchema = errors.New("Invalid schema")

happens when avro schema is unparsable or is invalid in any other way

View Source
var InvalidStringLength = errors.New("Invalid string length")

happens when given value to decode as string has either negative or undecodable length

View Source
var InvalidSync = errors.New("Invalid sync")

happens when file header's sync and block's sync do not match - indicates corrupted data

View Source
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

View Source
var LongOverflow = errors.New("Overflowed a long value")

happens when the given value to decode overflows maximum int64 value

View Source
var MAGIC []byte = []byte{'O', 'b', 'j', VERSION}
View Source
var NegativeBytesLength = errors.New("Negative bytes length")

happens when given value to decode as bytes has negative length

View Source
var NestedUnionsNotAllowed = errors.New("Nested unions are not allowed")

happens when avro schema contains a union within union

View Source
var NotAvroFile = errors.New("Not an Avro data file")

indicates the given file to decode does not correspond to Avro data file format

View Source
var SCHEMA_KEY = "avro.schema"
View Source
var SYNC_SIZE = 16
View Source
var SchemaNotSet = errors.New("Schema not set")

happens when a datum reader has no set schema

View Source
var VERSION byte = 1

Functions

This section is empty.

Types

type ArraySchema

type ArraySchema struct {
	Items Schema
}

func (*ArraySchema) GetName

func (*ArraySchema) GetName() string

func (*ArraySchema) MarshalJSON

func (this *ArraySchema) MarshalJSON() ([]byte, error)

func (*ArraySchema) String

func (this *ArraySchema) String() string

func (*ArraySchema) Type

func (*ArraySchema) Type() int

type BinaryDecoder

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

func NewBinaryDecoder

func NewBinaryDecoder(buf []byte) *BinaryDecoder

func (*BinaryDecoder) ArrayNext

func (this *BinaryDecoder) ArrayNext() (int64, error)

func (*BinaryDecoder) MapNext

func (this *BinaryDecoder) MapNext() (int64, error)

func (*BinaryDecoder) ReadArrayStart

func (this *BinaryDecoder) ReadArrayStart() (int64, error)

func (*BinaryDecoder) ReadBoolean

func (this *BinaryDecoder) ReadBoolean() (bool, error)

func (*BinaryDecoder) ReadBytes

func (this *BinaryDecoder) ReadBytes() ([]byte, error)

func (*BinaryDecoder) ReadDouble

func (this *BinaryDecoder) ReadDouble() (float64, error)

func (*BinaryDecoder) ReadEnum

func (this *BinaryDecoder) ReadEnum() (int32, error)

func (*BinaryDecoder) ReadFixed

func (this *BinaryDecoder) ReadFixed(bytes []byte) error

func (*BinaryDecoder) ReadFixedWithBounds

func (this *BinaryDecoder) ReadFixedWithBounds(bytes []byte, start int, length int) error

func (*BinaryDecoder) ReadFloat

func (this *BinaryDecoder) ReadFloat() (float32, error)

func (*BinaryDecoder) ReadInt

func (this *BinaryDecoder) ReadInt() (int32, error)

func (*BinaryDecoder) ReadLong

func (this *BinaryDecoder) ReadLong() (int64, error)

func (*BinaryDecoder) ReadMapStart

func (this *BinaryDecoder) ReadMapStart() (int64, error)

func (*BinaryDecoder) ReadNull

func (this *BinaryDecoder) ReadNull() (interface{}, error)

func (*BinaryDecoder) ReadString

func (this *BinaryDecoder) ReadString() (string, error)

func (*BinaryDecoder) Seek

func (this *BinaryDecoder) Seek(pos int64)

func (*BinaryDecoder) SetBlock

func (this *BinaryDecoder) SetBlock(block *DataBlock)

func (*BinaryDecoder) Tell

func (this *BinaryDecoder) Tell() int64

type BinaryEncoder

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

func NewBinaryEncoder

func NewBinaryEncoder(buffer *bytes.Buffer) *BinaryEncoder

func (*BinaryEncoder) WriteArrayNext

func (this *BinaryEncoder) WriteArrayNext(count int64)

func (*BinaryEncoder) WriteArrayStart

func (this *BinaryEncoder) WriteArrayStart(count int64)

func (*BinaryEncoder) WriteBoolean

func (this *BinaryEncoder) WriteBoolean(x bool)

func (*BinaryEncoder) WriteBytes

func (this *BinaryEncoder) WriteBytes(x []byte)

func (*BinaryEncoder) WriteDouble

func (this *BinaryEncoder) WriteDouble(x float64)

func (*BinaryEncoder) WriteFloat

func (this *BinaryEncoder) WriteFloat(x float32)

func (*BinaryEncoder) WriteInt

func (this *BinaryEncoder) WriteInt(x int32)

func (*BinaryEncoder) WriteLong

func (this *BinaryEncoder) WriteLong(x int64)

func (*BinaryEncoder) WriteMapNext

func (this *BinaryEncoder) WriteMapNext(count int64)

func (*BinaryEncoder) WriteMapStart

func (this *BinaryEncoder) WriteMapStart(count int64)

func (*BinaryEncoder) WriteNull

func (this *BinaryEncoder) WriteNull(_ interface{})

func (*BinaryEncoder) WriteString

func (this *BinaryEncoder) WriteString(x string)

type BooleanSchema

type BooleanSchema struct{}

func (*BooleanSchema) GetName

func (*BooleanSchema) GetName() string

func (*BooleanSchema) MarshalJSON

func (this *BooleanSchema) MarshalJSON() ([]byte, error)

func (*BooleanSchema) String

func (*BooleanSchema) String() string

func (*BooleanSchema) Type

func (*BooleanSchema) Type() int

type BytesSchema

type BytesSchema struct{}

func (*BytesSchema) GetName

func (*BytesSchema) GetName() string

func (*BytesSchema) MarshalJSON

func (this *BytesSchema) MarshalJSON() ([]byte, error)

func (*BytesSchema) String

func (*BytesSchema) String() string

func (*BytesSchema) Type

func (*BytesSchema) Type() int

type DataBlock

type DataBlock struct {
	Data           []byte
	NumEntries     int64
	BlockSize      int
	BlockRemaining int64
}

type DataFileReader

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

func NewDataFileReader

func NewDataFileReader(filename string, datumReader DatumReader) (*DataFileReader, error)

func (*DataFileReader) Next

func (this *DataFileReader) Next(v interface{}) (bool, error)

func (*DataFileReader) NextBlock

func (this *DataFileReader) NextBlock() error

func (*DataFileReader) Seek

func (this *DataFileReader) Seek(pos int64)

type DatumReader

type DatumReader interface {
	Read(interface{}, Decoder) (interface{}, error)
	SetSchema(Schema)
}

type DatumWriter

type DatumWriter interface {
	SetSchema(Schema)
	Write(interface{}, Encoder)
}

type Decoder

type Decoder interface {
	ReadNull() (interface{}, error)
	ReadBoolean() (bool, error)
	ReadInt() (int32, error)
	ReadLong() (int64, error)
	ReadFloat() (float32, error)
	ReadDouble() (float64, error)
	ReadBytes() ([]byte, error)
	ReadString() (string, error)
	ReadEnum() (int32, error)
	ReadArrayStart() (int64, error)
	ArrayNext() (int64, error)
	ReadMapStart() (int64, error)
	MapNext() (int64, error)
	ReadFixed([]byte) error
	ReadFixedWithBounds([]byte, int, int) error
	SetBlock(*DataBlock)
	Seek(int64)
	Tell() int64
}

type DoubleSchema

type DoubleSchema struct{}

func (*DoubleSchema) GetName

func (*DoubleSchema) GetName() string

func (*DoubleSchema) MarshalJSON

func (this *DoubleSchema) MarshalJSON() ([]byte, error)

func (*DoubleSchema) String

func (*DoubleSchema) String() string

func (*DoubleSchema) Type

func (*DoubleSchema) Type() int

type Encoder

type Encoder interface {
	WriteNull(interface{})
	WriteBoolean(bool)
	WriteInt(int32)
	WriteLong(int64)
	WriteFloat(float32)
	WriteDouble(float64)
	WriteBytes([]byte)
	WriteString(string)
	WriteArrayStart(int64)
	WriteArrayNext(int64)
	WriteMapStart(int64)
	WriteMapNext(int64)
}

type EnumSchema

type EnumSchema struct {
	Name      string
	Namespace string
	Aliases   []string
	Doc       string
	Symbols   []string
}

func (*EnumSchema) GetName

func (this *EnumSchema) GetName() string

func (*EnumSchema) MarshalJSON

func (this *EnumSchema) MarshalJSON() ([]byte, error)

func (*EnumSchema) String

func (this *EnumSchema) String() string

func (*EnumSchema) Type

func (*EnumSchema) Type() int

type FixedSchema

type FixedSchema struct {
	Name string
	Size int
}

func (*FixedSchema) GetName

func (this *FixedSchema) GetName() string

func (*FixedSchema) MarshalJSON

func (this *FixedSchema) MarshalJSON() ([]byte, error)

func (*FixedSchema) String

func (this *FixedSchema) String() string

func (*FixedSchema) Type

func (*FixedSchema) Type() int

type FloatSchema

type FloatSchema struct{}

func (*FloatSchema) GetName

func (*FloatSchema) GetName() string

func (*FloatSchema) MarshalJSON

func (this *FloatSchema) MarshalJSON() ([]byte, error)

func (*FloatSchema) String

func (*FloatSchema) String() string

func (*FloatSchema) Type

func (*FloatSchema) Type() int

type GenericDatumReader

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

func NewGenericDatumReader

func NewGenericDatumReader() *GenericDatumReader

func (*GenericDatumReader) Read

func (this *GenericDatumReader) Read(v interface{}, dec Decoder) (interface{}, error)

func (*GenericDatumReader) SetSchema

func (this *GenericDatumReader) SetSchema(schema Schema)

type GenericDatumWriter

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

func NewGenericDatumWriter

func NewGenericDatumWriter() *GenericDatumWriter

func (*GenericDatumWriter) SetSchema

func (this *GenericDatumWriter) SetSchema(schema Schema)

func (*GenericDatumWriter) Write

func (this *GenericDatumWriter) Write(obj interface{}, enc Encoder) error

type GenericEnum

type GenericEnum struct {
	Symbols []string
	// contains filtered or unexported fields
}

func (*GenericEnum) Get

func (this *GenericEnum) Get() string

type GenericRecord

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

func NewGenericRecord

func NewGenericRecord(schema Schema) *GenericRecord

func (*GenericRecord) Get

func (this *GenericRecord) Get(name string) interface{}

func (*GenericRecord) Schema

func (this *GenericRecord) Schema() Schema

func (*GenericRecord) Set

func (this *GenericRecord) Set(name string, value interface{})

type IntSchema

type IntSchema struct{}

func (*IntSchema) GetName

func (*IntSchema) GetName() string

func (*IntSchema) MarshalJSON

func (this *IntSchema) MarshalJSON() ([]byte, error)

func (*IntSchema) String

func (*IntSchema) String() string

func (*IntSchema) Type

func (*IntSchema) Type() int

type LongSchema

type LongSchema struct{}

func (*LongSchema) GetName

func (*LongSchema) GetName() string

func (*LongSchema) MarshalJSON

func (this *LongSchema) MarshalJSON() ([]byte, error)

func (*LongSchema) String

func (*LongSchema) String() string

func (*LongSchema) Type

func (*LongSchema) Type() int

type MapSchema

type MapSchema struct {
	Values Schema
}

func (*MapSchema) GetName

func (*MapSchema) GetName() string

func (*MapSchema) MarshalJSON

func (this *MapSchema) MarshalJSON() ([]byte, error)

func (*MapSchema) String

func (this *MapSchema) String() string

func (*MapSchema) Type

func (*MapSchema) Type() int

type NullSchema

type NullSchema struct{}

func (*NullSchema) GetName

func (*NullSchema) GetName() string

func (*NullSchema) MarshalJSON

func (this *NullSchema) MarshalJSON() ([]byte, error)

func (*NullSchema) String

func (*NullSchema) String() string

func (*NullSchema) Type

func (*NullSchema) Type() int

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"`
	Fields    []*SchemaField `json:"fields,omitempty"`
}

COMPLEX

func (*RecordSchema) GetName

func (this *RecordSchema) GetName() string

func (*RecordSchema) MarshalJSON

func (this *RecordSchema) MarshalJSON() ([]byte, error)

func (*RecordSchema) String

func (this *RecordSchema) String() string

func (*RecordSchema) Type

func (*RecordSchema) Type() int

type Schema

type Schema interface {
	Type() int
	GetName() string
	String() string
}

func ParseSchema

func ParseSchema(rawSchema string) (Schema, error)

type SchemaField

type SchemaField struct {
	Name    string      `json:"name,omitempty"`
	Doc     string      `json:"doc,omitempty"`
	Default interface{} `json:"default,omitempty"`
	Type    Schema      `json:"type,omitempty"`
}

func (*SchemaField) String

func (this *SchemaField) String() string

type SpecificDatumReader

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

func NewSpecificDatumReader

func NewSpecificDatumReader() *SpecificDatumReader

func (*SpecificDatumReader) Read

func (this *SpecificDatumReader) Read(v interface{}, dec Decoder) (interface{}, error)

func (*SpecificDatumReader) SetSchema

func (this *SpecificDatumReader) SetSchema(schema Schema)

type SpecificDatumWriter

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

func NewSpecificDatumWriter

func NewSpecificDatumWriter() *SpecificDatumWriter

func (*SpecificDatumWriter) SetSchema

func (this *SpecificDatumWriter) SetSchema(schema Schema)

func (*SpecificDatumWriter) Write

func (this *SpecificDatumWriter) Write(obj interface{}, enc Encoder) error

type StringSchema

type StringSchema struct{}

PRIMITIVES

func (*StringSchema) GetName

func (*StringSchema) GetName() string

func (*StringSchema) MarshalJSON

func (this *StringSchema) MarshalJSON() ([]byte, error)

func (*StringSchema) String

func (*StringSchema) String() string

func (*StringSchema) Type

func (*StringSchema) Type() int

type UnionSchema

type UnionSchema struct {
	Types []Schema
}

func (*UnionSchema) GetName

func (*UnionSchema) GetName() string

func (*UnionSchema) MarshalJSON

func (this *UnionSchema) MarshalJSON() ([]byte, error)

func (*UnionSchema) String

func (this *UnionSchema) String() string

func (*UnionSchema) Type

func (*UnionSchema) Type() int

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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