package ocf

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

Dependency Relation
	imports 14 packages, and imported by one package

Involved Source Files codec.go Package ocf implements encoding and decoding of Avro Object Container Files as defined by the Avro specification. See the Avro specification for an understanding of Avro: http://avro.apache.org/docs/current/
Code Examples package main import ( "log" "os" "github.com/hamba/avro/v2/ocf" ) func main() { type SimpleRecord struct { A int64 `avro:"a"` B string `avro:"b"` } f, err := os.Open("/your/avro/file.avro") if err != nil { log.Fatal(err) } defer f.Close() dec, err := ocf.NewDecoder(f) if err != nil { log.Fatal(err) } for dec.HasNext() { var record SimpleRecord err = dec.Decode(&record) if err != nil { log.Fatal(err) } // Do something with the data } if err := dec.Error(); err != nil { log.Fatal(err) } } package main import ( "log" "os" "github.com/hamba/avro/v2/ocf" ) 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"` } f, err := os.Open("/your/avro/file.avro") if err != nil { log.Fatal(err) } defer f.Close() enc, err := ocf.NewEncoder(schema, f) if err != nil { log.Fatal(err) } var record SimpleRecord err = enc.Encode(record) if err != nil { log.Fatal(err) } if err := enc.Flush(); err != nil { log.Fatal(err) } if err := f.Sync(); err != nil { log.Fatal(err) } }
Package-Level Type Names (total 11)
/* sort by: | */
Codec represents a compression codec. Decode decodes the given bytes. Encode encodes the given bytes. *DeflateCodec *NullCodec *SnappyCodec *ZStandardCodec
CodecName represents a compression codec name. func WithCodec(codec CodecName) EncoderFunc const Deflate const Null const Snappy const ZStandard
Decoder reads and decodes Avro values from a container file. Decode reads the next Avro encoded value from its input and stores it in the value pointed to by v. Error returns the last reader error. HasNext determines if there is another value to read. Metadata returns the header metadata. Schema returns the schema that was parsed from the file's metadata and that is used to interpret the file's contents. *Decoder : github.com/grpc-ecosystem/grpc-gateway/v2/runtime.Decoder func NewDecoder(r io.Reader, opts ...DecoderFunc) (*Decoder, error)
DecoderFunc represents a configuration function for Decoder. func WithDecoderConfig(wCfg avro.API) DecoderFunc func WithDecoderSchemaCache(cache *avro.SchemaCache) DecoderFunc func WithZStandardDecoderOptions(opts ...zstd.DOption) DecoderFunc func NewDecoder(r io.Reader, opts ...DecoderFunc) (*Decoder, error)
DeflateCodec is a flate compression codec. Decode decodes the given bytes. Encode encodes the given bytes. *DeflateCodec : Codec
Encoder writes Avro container file to an output stream. Close closes the encoder, flushing the writer. Encode writes the Avro encoding of v to the stream. Flush flushes the underlying writer. Write v to the internal buffer. This method skips the internal encoder and therefore the caller is responsible for encoding the bytes. No error will be thrown if the bytes does not conform to the schema given to NewEncoder, but the final ocf data will be corrupted. *Encoder : github.com/apache/thrift/lib/go/thrift.Flusher *Encoder : github.com/grpc-ecosystem/grpc-gateway/v2/runtime.Encoder *Encoder : github.com/miekg/dns.Writer *Encoder : github.com/prometheus/common/expfmt.Closer *Encoder : go.uber.org/zap/zapcore.ReflectedEncoder *Encoder : internal/bisect.Writer *Encoder : io.Closer *Encoder : io.WriteCloser *Encoder : io.Writer func NewEncoder(s string, w io.Writer, opts ...EncoderFunc) (*Encoder, error) func NewEncoderWithSchema(schema avro.Schema, w io.Writer, opts ...EncoderFunc) (*Encoder, error)
EncoderFunc represents a configuration function for Encoder. func WithBlockLength(length int) EncoderFunc func WithBlockSize(size int) EncoderFunc func WithCodec(codec CodecName) EncoderFunc func WithCompressionLevel(compLvl int) EncoderFunc func WithEncoderSchemaCache(cache *avro.SchemaCache) EncoderFunc func WithEncodingConfig(wCfg avro.API) EncoderFunc func WithMetadata(meta map[string][]byte) EncoderFunc func WithMetadataKeyVal(key string, val []byte) EncoderFunc func WithSchemaMarshaler(m func(avro.Schema) ([]byte, error)) EncoderFunc func WithSyncBlock(sync [16]byte) EncoderFunc func WithZStandardEncoderOptions(opts ...zstd.EOption) EncoderFunc func NewEncoder(s string, w io.Writer, opts ...EncoderFunc) (*Encoder, error) func NewEncoderWithSchema(schema avro.Schema, w io.Writer, opts ...EncoderFunc) (*Encoder, error)
Header represents an Avro container file header. Magic [4]byte Meta map[string][]byte Sync [16]byte
NullCodec is a no op codec. Decode decodes the given bytes. Encode encodes the given bytes. *NullCodec : Codec
SnappyCodec is a snappy compression codec. Decode decodes the given bytes. Encode encodes the given bytes. *SnappyCodec : Codec
ZStandardCodec is a zstandard compression codec. Decode decodes the given bytes. Encode encodes the given bytes. *ZStandardCodec : Codec
Package-Level Functions (total 17)
NewDecoder returns a new decoder that reads from reader r.
NewEncoder returns a new encoder that writes to w using schema s. If the writer is an existing ocf file, it will append data using the existing schema.
NewEncoderWithSchema returns a new encoder that writes to w using schema s. If the writer is an existing ocf file, it will append data using the existing schema.
WithBlockLength sets the block length on the encoder.
WithBlockSize sets the maximum uncompressed size of a buffered block before it is written and flushed to the underlying io.Writer (after compression).
WithCodec sets the compression codec on the encoder.
WithCompressionLevel sets the compression codec to deflate and the compression level on the encoder.
WithDecoderConfig sets the value decoder config on the OCF decoder.
WithDecoderSchemaCache sets the schema cache for the decoder. If not specified, defaults to avro.DefaultSchemaCache.
WithEncoderSchemaCache sets the schema cache for the encoder. If not specified, defaults to avro.DefaultSchemaCache.
WithEncodingConfig sets the value encoder config on the OCF encoder.
WithMetadata sets the metadata on the encoder header.
WithMetadataKeyVal sets a single key-value pair for the metadata on the encoder header.
WithSchemaMarshaler sets the schema marshaler for the encoder. If not specified, defaults to DefaultSchemaMarshaler.
WithSyncBlock sets the sync block.
WithZStandardDecoderOptions sets the options for the ZStandard decoder.
WithZStandardEncoderOptions sets the options for the ZStandard encoder.
Package-Level Variables (total 3)
DefaultSchemaMarshaler calls the schema's String() method, to produce a "canonical" schema.
FullSchemaMarshaler calls the schema's MarshalJSON() method, to produce a schema with all details preserved. The "canonical" schema returned by the default marshaler does not preserve a type's extra properties.
HeaderSchema is the Avro schema of a container file header.
Package-Level Constants (total 4)
Supported compression codecs.
Supported compression codecs.
Supported compression codecs.
Supported compression codecs.