Documentation
¶
Index ¶
- Variables
- func BuildHeader(schema avro.Schema) ([]byte, error)
- func BuildHeaderForFingerprint(fingerprint []byte) ([]byte, error)
- func ComputeFingerprint(schema avro.Schema) ([]byte, error)
- func GetSchema[T AvroGenerated]() avro.Schema
- func ParseHeader(data []byte) ([]byte, []byte, error)
- type AvroGenerated
- type Codec
- type DynamicDecoder
- type SchemaResolver
- type TypedCodec
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownSchema = errors.New("unknown schema")
ErrUnknownSchema is an API error that must be returned if the requested schema is not known to a resolver.
var Magic = []byte{0xc3, 0x01}
Magic is the two-byte magic marker described in: https://avro.apache.org/docs/1.10.2/spec.html#single_object_encoding
Functions ¶
func BuildHeader ¶
BuildHeader builds an SOE header from a schema's fingerprint.
func BuildHeaderForFingerprint ¶
BuildHeaderForFingerprint builds an SOE header from a fingerprint.
func ComputeFingerprint ¶
ComputeFingerprint returns an SOE-compatible (CRC64, little-endian) schema fingerprint.
func GetSchema ¶
func GetSchema[T AvroGenerated]() avro.Schema
GetSchema returns the avro.Schema associated with type T.
Types ¶
type AvroGenerated ¶
type AvroGenerated interface {
Unmarshal(b []byte) error
Marshal() ([]byte, error)
Schema() avro.Schema
}
AvroGenerated is implemented by all avrogen-generated Avro types.
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
Codec marshals values to/from bytes, with the Avro binary payload wrapped in an SOE frame containing the writer schema fingerprint.
func NewCodecWithAPI ¶
NewCodecWithAPI creates a new Codec for a Schema and an API.
func (*Codec) Decode ¶
Decode unmarshals a value from SOE-encoded Avro binary, and fails if the schema fingerprint doesn't match the held schema.
func (*Codec) DecodeUnverified ¶
DecodeUnverified unmarshals a value from SOE-encoded Avro binary without validating the schema fingerprint.
type DynamicDecoder ¶
type DynamicDecoder struct {
// contains filtered or unexported fields
}
DynamicDecoder unmarshals SOE-framed records. It will use a schema resolver to lookup schemas for every record, and deserialize using exactly the writer schema. This makes it possible to decode records from entirely disparate schemas into the same Go type.
func NewDynamicDecoder ¶
func NewDynamicDecoder(resolver SchemaResolver) *DynamicDecoder
NewDynamicDecoder returns a new DynamicDecoder for a resolver the default config.
func NewDynamicDecoderWithAPI ¶
func NewDynamicDecoderWithAPI(resolver SchemaResolver, api avro.API) *DynamicDecoder
NewDynamicDecoderWithAPI returns a new DynamicDecoder for the given resolver and API.
type SchemaResolver ¶
type SchemaResolver interface {
// GetSchema must return ErrUnknownSchema if no schema is found for
// fingerprint. All other errors are unexpected.
GetSchema(ctx context.Context, fingerprint []byte) (avro.Schema, error)
}
SchemaResolver implementations are expected to be callable for every record, so should cache expensive schema lookups.
type TypedCodec ¶
type TypedCodec[T any] struct { // contains filtered or unexported fields }
TypedCodec marshals/unmarshals AvroGenerated values to/from SOE-framed Avro binary payloads. Must be instantiated with a pointer type, e.g.
c, _ := NewTypedCodec[*MyType]() var val MyType c.Encode(&val) c.Decode(&val) var badVal any c.Encode(badVal) // cannot use badVal (variable of type any)...
It is a strongly typed version of soe.Codec.
func NewTypedCodec ¶
func NewTypedCodec[T AvroGenerated]() (*TypedCodec[T], error)
NewTypedCodec creates a new TypedCodec for type T and the default config.
func NewTypedCodecWithAPI ¶
func NewTypedCodecWithAPI[T AvroGenerated](api avro.API) (*TypedCodec[T], error)
NewTypedCodecWithAPI creates a new TypedCodec for type T and an API.
func (*TypedCodec[T]) Decode ¶
func (c *TypedCodec[T]) Decode(data []byte, v T) error
Decode unmarshals a typed value from SOE-encoded Avro binary, and fails if the schema fingerprint doesn't match the held schema.
func (*TypedCodec[T]) DecodeUnverified ¶
func (c *TypedCodec[T]) DecodeUnverified(data []byte, v T) error
DecodeUnverified unmarshals a typed value from SOE-encoded Avro binary without validating the schema fingerprint.
func (*TypedCodec[T]) Encode ¶
func (c *TypedCodec[T]) Encode(v T) ([]byte, error)
Encode marshals a typed value to SOE-encoded Avro binary.