avro

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 16 Imported by: 67

README

Logo

Go Report Card Build Status Coverage Status GoDoc GitHub release GitHub license

A fast Go avro codec

Overview

Install with:

go get github.com/hamba/avro

Usage

type SimpleRecord struct {
	A int64  `avro:"a"`
	B string `avro:"b"`
}

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)
}

in := SimpleRecord{A: 27, B: "foo"}

data, err := avro.Marshal(schema, in)
if err != nil {
	log.Fatal(err)
}

fmt.Println(data)
// Outputs: [54 6 102 111 111]

out := SimpleRecord{}
err = avro.Unmarshal(schema, data, &out)
if err != nil {
	log.Fatal(err)
}

fmt.Println(out)
// Outputs: {27 foo}

More examples in the godoc.

Types Conversions
Avro Go Struct Go Interface
null nil nil
boolean bool bool
bytes []byte []byte
float float32 float32
double float64 float64
long int64 int64
int int, int32, int16, int8 int
string string string
array []T []interface{}
enum string string
fixed [n]byte []byte
map map[string]T{} map[string]interface{}
record struct map[string]interface{}
union see below see below
Unions

In Go structs, the following types are accepted: map[string]interface{}, *T, and a struct implementing avro.UnionType. When en/decoding to an interface{}, a map[string]interface{} will always be used.

  • map[string]interface{}: If the union value is nil, a nil map will be en/decoded. When a non-nil union value is encountered, a single key is en/decoded. The key is the avro type name, or scheam full name in the case of a named schema (enum, fixed or record).
  • *T: This is allowed in a "nullable" union. A nullable union is defined as a two schema union, with the first being null (ie. ["null", "string"]), in this case a *T is allowed, with T matching the conversion table above.
  • avro.UnionType: A struct in implementing avro.UnionType can be provided, allowing for strong type encoding. An example can be found in the godoc.

Benchmark

Benchmark source code can be found at: https://github.com/nrwiersma/avro-benchmarks

BenchmarkGoAvroDecode-8     	  300000	      3863 ns/op	     442 B/op	      27 allocs/op
BenchmarkGoAvroEncode-8     	  300000	      4677 ns/op	     841 B/op	      63 allocs/op
BenchmarkHambaDecode-8      	 2000000	       655 ns/op	      64 B/op	       4 allocs/op
BenchmarkHambaEncode-8      	 3000000	       577 ns/op	     200 B/op	       3 allocs/op
BenchmarkLinkedinDecode-8   	 1000000	      2175 ns/op	    1776 B/op	      40 allocs/op
BenchmarkLinkedinEncode-8   	 2000000	       816 ns/op	     288 B/op	      10 allocs/op

Always benchmark with your own workload. The result depends heavily on the data input.

TODO

  • Logical Types
  • Schema
    • Refactor parsing to be cleaner
    • Better schema validation
    • Aliases
  • Avro Textual Form?

Documentation

Overview

Package avro implements encoding and decoding of Avro as defined by the Avro specification.

See the Avro specification for an understanding of Avro: http://avro.apache.org/docs/current/

Example (Usage)
package main

import (
	"fmt"
	"log"

	"github.com/hamba/avro"
)

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)
	// Outputs: [54 6 102 111 111]

	out := SimpleRecord{}
	err = avro.Unmarshal(schema, data, &out)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%+v\n", out)
	// Outputs: {A:27 B:foo}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{}.Freeze()

DefaultConfig is the default API.

Functions

func Marshal

func Marshal(schema Schema, v interface{}) ([]byte, error)

Marshal returns the Avro encoding of v.

Example
package main

import (
	"fmt"
	"os"

	"github.com/hamba/avro"
)

func main() {
	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{}
	b, err := avro.Marshal(schema, simple)
	if err != nil {
		fmt.Println("error:", err)
	}

	os.Stdout.Write(b)
}
Output:

func Unmarshal

func Unmarshal(schema Schema, data []byte, v interface{}) error

Unmarshal parses the Avro encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an error.

Example
package main

import (
	"fmt"

	"github.com/hamba/avro"
)

func main() {
	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{} // Your Avro data here
	simple := SimpleRecord{}
	if err := avro.Unmarshal(schema, data, &simple); err != nil {
		fmt.Println("error:", err)
	}

	fmt.Printf("%+v", simple)
}
Output:

Types

type API

type API interface {
	// Marshal returns the Avro encoding of v.
	Marshal(schema Schema, v interface{}) ([]byte, error)

	// Unmarshal parses the Avro encoded data and stores the result in the value pointed to by v.
	// If v is nil or not a pointer, Unmarshal returns an error.
	Unmarshal(schema Schema, data []byte, v interface{}) error

	// NewEncoder returns a new encoder that writes to w using schema.
	NewEncoder(schema Schema, w io.Writer) *Encoder

	// NewDecoder returns a new decoder that reads from reader r using schema.
	NewDecoder(schema Schema, r io.Reader) *Decoder

	// DecoderOf returns the value decoder for a given schema and type.
	DecoderOf(schema Schema, typ reflect2.Type) ValDecoder

	// EncoderOf returns the value encoder for a given schema and type.
	EncoderOf(schema Schema, tpy reflect2.Type) ValEncoder
}

API represents a frozen Config.

type ArraySchema

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

ArraySchema is an Avro array type schema.

func (*ArraySchema) Fingerprint

func (s *ArraySchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*ArraySchema) Items

func (s *ArraySchema) Items() Schema

Items returns the items schema of an array.

func (*ArraySchema) String

func (s *ArraySchema) String() string

String returns the canonical form of the schema.

func (*ArraySchema) Type

func (s *ArraySchema) Type() Type

Type returns the type of the schema.

type Config

type Config struct {
	// TagKey is the struct tag key used when en/decoding structs.
	// This defaults to "avro".
	TagKey string

	// BlockLength is the length of blocks for maps and arrays.
	// This defaults to 100.
	BlockLength int
}

Config customises how the codec should behave.

func (Config) Freeze

func (c Config) Freeze() API

Freeze makes the configuration immutable.

type Decoder

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

Decoder reads and decodes Avro values from an input stream.

func NewDecoder

func NewDecoder(s string, r io.Reader) (*Decoder, error)

NewDecoder returns a new decoder that reads from reader r using schema s.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/hamba/avro"
)

func main() {
	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{}) // Your reader goes here
	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)
}
Output:

func NewDecoderForSchema

func NewDecoderForSchema(schema Schema, reader io.Reader) *Decoder

NewDecoderForSchema returns a new decoder that reads from r using schema.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/hamba/avro"
)

func main() {
	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{}) // Your reader goes here
	decoder := avro.NewDecoderForSchema(schema, r)

	simple := SimpleRecord{}
	if err := decoder.Decode(&simple); err != nil {
		fmt.Println("error:", err)
	}

	fmt.Printf("%+v", simple)
}
Output:

func (*Decoder) Decode

func (d *Decoder) Decode(obj interface{}) error

Decode reads the next Avro encoded value from its input and stores it in the value pointed to by v.

type Encoder

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

Encoder writes Avro values to an output stream.

func NewEncoder

func NewEncoder(s string, w io.Writer) (*Encoder, error)

NewEncoder returns a new encoder that writes to w using schema s.

Example
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/hamba/avro"
)

func main() {
	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{}
	if err := encoder.Encode(simple); err != nil {
		fmt.Println("error:", err)
	}

	os.Stdout.Write(w.Bytes())
}
Output:

func NewEncoderForSchema

func NewEncoderForSchema(schema Schema, w io.Writer) *Encoder

NewEncoderForSchema returns a new encoder that writes to w using schema.

Example
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/hamba/avro"
)

func main() {
	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{}
	if err := encoder.Encode(simple); err != nil {
		fmt.Println("error:", err)
	}

	os.Stdout.Write(w.Bytes())
}
Output:

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encode writes the Avro encoding of v to the stream.

type EnumSchema

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

EnumSchema is an Avro enum type schema.

func (*EnumSchema) Fingerprint

func (s *EnumSchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*EnumSchema) Name

func (s *EnumSchema) Name() string

Name implements the NamedSchema interface.

func (*EnumSchema) String

func (s *EnumSchema) String() string

String returns the canonical form of the schema.

func (*EnumSchema) Symbols

func (s *EnumSchema) Symbols() []string

Symbols returns the symbols of an enum.

func (*EnumSchema) Type

func (s *EnumSchema) Type() Type

Type returns the type of the schema.

type Field

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

Field is an Avro record type field.

func (*Field) Default

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

Default returns the default of a field or nil.

The only time a nil default is valid is for a Null Type.

func (*Field) Name

func (s *Field) Name() string

Name returns the name of a field.

func (*Field) String

func (s *Field) String() string

String returns the canonical form of a field.

func (*Field) Type

func (s *Field) Type() Schema

Type returns the schema of a field.

type FixedSchema

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

FixedSchema is an Avro fixed type schema.

func (*FixedSchema) Fingerprint

func (s *FixedSchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*FixedSchema) Name

func (s *FixedSchema) Name() string

Name implements the NamedSchema interface.

func (*FixedSchema) Size

func (s *FixedSchema) Size() int

Size returns the number of bytes of the fixed schema.

func (*FixedSchema) String

func (s *FixedSchema) String() string

String returns the canonical form of the schema.

func (*FixedSchema) Type

func (s *FixedSchema) Type() Type

Type returns the type of the schema.

type MapSchema

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

MapSchema is an Avro map type schema.

func (*MapSchema) Fingerprint

func (s *MapSchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*MapSchema) String

func (s *MapSchema) String() string

String returns the canonical form of the schema.

func (*MapSchema) Type

func (s *MapSchema) Type() Type

Type returns the type of the schema.

func (*MapSchema) Values

func (s *MapSchema) Values() Schema

Values returns the values schema of a map.

type NamedSchema

type NamedSchema interface {
	Schema

	// Name returns the fill name of the schema.
	Name() string
}

NamedSchema represents a schema with a name.

type NullSchema

type NullSchema struct{}

NullSchema is an Avro null type schema.

func (*NullSchema) Fingerprint

func (s *NullSchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*NullSchema) String

func (s *NullSchema) String() string

String returns the canonical form of the schema.

func (*NullSchema) Type

func (s *NullSchema) Type() Type

Type returns the type of the schema.

type PrimitiveSchema

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

PrimitiveSchema is an Avro primitive type schema.

func NewPrimitiveSchema

func NewPrimitiveSchema(t Type) *PrimitiveSchema

NewPrimitiveSchema creates a new PrimitiveSchema.

func (*PrimitiveSchema) Fingerprint

func (s *PrimitiveSchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*PrimitiveSchema) String

func (s *PrimitiveSchema) String() string

String returns the canonical form of the schema.

func (*PrimitiveSchema) Type

func (s *PrimitiveSchema) Type() Type

Type returns the type of the schema.

type Reader

type Reader struct {
	Error error
	// contains filtered or unexported fields
}

Reader is an Avro specific io.Reader.

func NewReader

func NewReader(r io.Reader, bufSize int, opts ...ReaderFunc) *Reader

NewReader creates a new Reader.

func (*Reader) Read

func (r *Reader) Read(b []byte)

Read reads data into the given bytes.

func (*Reader) ReadArrayCB

func (r *Reader) ReadArrayCB(callback func(*Reader) bool)

ReadArrayCB reads an array with a callback per item.

func (*Reader) ReadBlockHeader

func (r *Reader) ReadBlockHeader() (int64, int64)

ReadBlockHeader reads a Block Header from the Reader.

func (*Reader) ReadBool

func (r *Reader) ReadBool() bool

ReadBool reads a Bool from the Reader.

func (*Reader) ReadBytes

func (r *Reader) ReadBytes() []byte

ReadBytes reads Bytes from the Reader.

func (*Reader) ReadDouble

func (r *Reader) ReadDouble() float64

ReadDouble reads a Double from the Reader.

func (*Reader) ReadFloat

func (r *Reader) ReadFloat() float32

ReadFloat reads a Float from the Reader.

func (*Reader) ReadInt

func (r *Reader) ReadInt() int32

ReadInt reads an Int from the Reader.

func (*Reader) ReadLong

func (r *Reader) ReadLong() int64

ReadLong reads a Long from the Reader.

func (*Reader) ReadMapCB

func (r *Reader) ReadMapCB(callback func(*Reader, string) bool)

ReadMapCB reads an array with a callback per item.

func (*Reader) ReadNext

func (r *Reader) ReadNext(schema Schema) interface{}

ReadNext reads the next Avro element as a generic interface.

func (*Reader) ReadString

func (r *Reader) ReadString() string

ReadString reads a String from the Reader.

func (*Reader) ReadVal

func (r *Reader) ReadVal(schema Schema, obj interface{})

ReadVal parses Avro value and stores the result in the value pointed to by obj.

func (*Reader) ReportError

func (r *Reader) ReportError(operation string, msg string)

ReportError record a error in iterator instance with current position.

func (*Reader) Reset

func (r *Reader) Reset(b []byte) *Reader

Reset resets a Reader with a new byte array attached.

func (*Reader) SkipBool

func (r *Reader) SkipBool()

SkipBool skips a Bool in the reader.

func (*Reader) SkipBytes

func (r *Reader) SkipBytes()

SkipBytes skips Bytes in the reader.

func (*Reader) SkipDouble

func (r *Reader) SkipDouble()

SkipDouble skips a Double in the reader.

func (*Reader) SkipFloat

func (r *Reader) SkipFloat()

SkipFloat skips a Float in the reader.

func (*Reader) SkipInt

func (r *Reader) SkipInt()

SkipInt skips an Int in the reader.

func (*Reader) SkipLong

func (r *Reader) SkipLong()

SkipLong skips a Long in the reader.

func (*Reader) SkipNBytes

func (r *Reader) SkipNBytes(n int)

SkipNBytes skips the given number of bytes in the reader.

func (*Reader) SkipString

func (r *Reader) SkipString()

SkipString skips a String in the reader.

type ReaderFunc

type ReaderFunc func(r *Reader)

ReaderFunc is a function used to customize the Reader.

func WithReaderConfig

func WithReaderConfig(cfg API) ReaderFunc

WithReaderConfig specifies the configuration to use with a reader.

type RecordSchema

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

RecordSchema is an Avro record type schema.

func (*RecordSchema) Fields

func (s *RecordSchema) Fields() []*Field

Fields returns the fields of a record.

func (*RecordSchema) Fingerprint

func (s *RecordSchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*RecordSchema) Name

func (s *RecordSchema) Name() string

Name implements the NamedSchema interface.

func (*RecordSchema) String

func (s *RecordSchema) String() string

String returns the canonical form of the schema.

func (*RecordSchema) Type

func (s *RecordSchema) Type() Type

Type returns the type of the schema.

type RefSchema

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

RefSchema is a reference to a named Avro schema.

func (*RefSchema) Fingerprint

func (s *RefSchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*RefSchema) Schema

func (s *RefSchema) Schema() Schema

Schema returns the schema being referenced.

func (*RefSchema) String

func (s *RefSchema) String() string

String returns the canonical form of the schema.

func (*RefSchema) Type

func (s *RefSchema) Type() Type

Type returns the type of the schema.

type Schema

type Schema interface {
	// Type returns the type of the schema.
	Type() Type

	// String returns the canonical form of the schema.
	String() string

	// Fingerprint returns the SHA256 fingerprint of the schema.
	Fingerprint() [32]byte
}

Schema represents an Avro schema

func MustParse

func MustParse(schema string) Schema

MustParse parses a schema string, panicing if there is an error.

func Parse

func Parse(schema string) (Schema, error)

Parse parses a schema string.

Example
package main

import (
	"fmt"
	"log"

	"github.com/hamba/avro"
)

func main() {
	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())
	// Outputs: record
}
Output:

func ParseFiles

func ParseFiles(paths ...string) (Schema, error)

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.

type Schemas

type Schemas []Schema

Schemas is a slice of Schemas.

func (Schemas) Get

func (s Schemas) Get(name string) (Schema, int)

Get gets a schema and position by type or name if it is a named schema.

type Type

type Type string

Type is a schema type

const (
	Record  Type = "record"
	Ref     Type = "<ref>"
	Enum    Type = "enum"
	Array   Type = "array"
	Map     Type = "map"
	Union   Type = "union"
	Fixed   Type = "fixed"
	String  Type = "string"
	Bytes   Type = "bytes"
	Int     Type = "int"
	Long    Type = "long"
	Float   Type = "float"
	Double  Type = "double"
	Boolean Type = "boolean"
	Null    Type = "null"
)

Schema type constants.

type UnionSchema

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

UnionSchema is an Avro union type schema.

func (*UnionSchema) Fingerprint

func (s *UnionSchema) Fingerprint() [32]byte

Fingerprint returns the SHA256 fingerprint of the schema.

func (*UnionSchema) Nullable

func (s *UnionSchema) Nullable() bool

Nullable returns the Schema if the union is nullable, otherwise nil.

func (*UnionSchema) String

func (s *UnionSchema) String() string

String returns the canonical form of the schema.

func (*UnionSchema) Type

func (s *UnionSchema) Type() Type

Type returns the type of the schema.

func (*UnionSchema) Types

func (s *UnionSchema) Types() Schemas

Types returns the types of a union.

type UnionType

type UnionType interface {
	Value() *interface{}
	SetType(string) error
	GetType() (string, error)
}

UnionType is the interface implemented by types that can resolve schema types/names to and from objects.

Example
package main

import (
	"fmt"
	"os"

	"github.com/hamba/avro"
)

type SimpleUnionType struct {
	Val interface{}
}

func (u *SimpleUnionType) Value() *interface{} {
	return &u.Val
}

func (u *SimpleUnionType) SetType(typ string) error {
	switch typ {
	case string(avro.String):
		u.Val = ""

	case string(avro.Int):
		u.Val = int(0)

	default:
		return fmt.Errorf("unknown type %s", typ)
	}

	return nil
}

func (u *SimpleUnionType) GetType() (string, error) {
	switch u.Val.(type) {
	case string:
		return string(avro.String), nil

	case int:
		return string(avro.Int), nil
	}

	return "", fmt.Errorf("unknown type %T", u.Val)
}

type UnionRecord struct {
	Items map[string]*SimpleUnionType `avro:"items"`
}

func main() {
	schema := avro.MustParse(`{
	    "type": "record",
	    "name": "union",
	    "namespace": "org.hamba.avro",
	    "fields" : [
	        {"name": "items", "type": {"type": "map", "values": ["string", "int"]}}
	    ]
	}`)

	record := UnionRecord{}
	b, err := avro.Marshal(schema, record)
	if err != nil {
		fmt.Println("error:", err)
	}

	os.Stdout.Write(b)
}
Output:

type ValDecoder

type ValDecoder interface {
	Decode(ptr unsafe.Pointer, r *Reader)
}

ValDecoder represents an internal value decoder.

You should never use ValDecoder directly.

type ValEncoder

type ValEncoder interface {
	Encode(ptr unsafe.Pointer, w *Writer)
}

ValEncoder represents an internal value encoder.

You should never use ValEncoder directly.

type Writer

type Writer struct {
	Error error
	// contains filtered or unexported fields
}

Writer is an Avro specific io.Writer.

func NewWriter

func NewWriter(out io.Writer, bufSize int, opts ...WriterFunc) *Writer

NewWriter creates a new Writer.

func (*Writer) Buffer

func (w *Writer) Buffer() []byte

Buffer gets the Writer buffer.

func (*Writer) Buffered

func (w *Writer) Buffered() int

Buffered returns the number of buffered bytes.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes any buffered data to the underlying io.Writer.

func (*Writer) Reset

func (w *Writer) Reset(out io.Writer)

Reset resets the Writer with a new io.Writer attached.

func (*Writer) Write

func (w *Writer) Write(b []byte)

Write writes raw bytes to the Writer.

func (*Writer) WriteBlockCB

func (w *Writer) WriteBlockCB(callback func(w *Writer) int64) int64

WriteBlockCB writes a block using the callback.

func (*Writer) WriteBlockHeader

func (w *Writer) WriteBlockHeader(l int64, s int64)

WriteBlockHeader writes a Block Header to the Writer.

func (*Writer) WriteBool

func (w *Writer) WriteBool(b bool)

WriteBool writes a Bool to the Writer.

func (*Writer) WriteBytes

func (w *Writer) WriteBytes(b []byte)

WriteBytes writes Bytes to the Writer.

func (*Writer) WriteDouble

func (w *Writer) WriteDouble(f float64)

WriteDouble writes a Double to the Writer.

func (*Writer) WriteFloat

func (w *Writer) WriteFloat(f float32)

WriteFloat writes a Float to the Writer.

func (*Writer) WriteInt

func (w *Writer) WriteInt(i int32)

WriteInt writes an Int to the Writer.

func (*Writer) WriteLong

func (w *Writer) WriteLong(i int64)

WriteLong writes a Long to the Writer.

func (*Writer) WriteString

func (w *Writer) WriteString(s string)

WriteString reads a String to the Writer.

func (*Writer) WriteVal

func (w *Writer) WriteVal(schema Schema, val interface{})

WriteVal writes the Avro encoding of obj.

type WriterFunc

type WriterFunc func(w *Writer)

WriterFunc is a function used to customize the Writer.

func WithWriterConfig

func WithWriterConfig(cfg API) WriterFunc

WithWriterConfig specifies the configuration to use with a writer.

Directories

Path Synopsis
internal
Package container implements encoding and decoding of Avro Object Container Files as defined by the Avro specification.
Package container implements encoding and decoding of Avro Object Container Files as defined by the Avro specification.
Package registry implements a Confluent Schema Registry compliant client.
Package registry implements a Confluent Schema Registry compliant client.

Jump to

Keyboard shortcuts

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