Documentation ¶
Index ¶
Constants ¶
const Type = sr.TypeAvro
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema represents an Avro schema. It exposes methods for marshaling and unmarshaling data.
func SchemaForType ¶
SchemaForType uses reflection to extract an Avro schema from v. Maps are regarded as structs.
func (*Schema) Marshal ¶
Marshal returns the Avro encoding of v. Note that this function may mutate v. Limitations: - Map keys need to be of type string - Array values need to be of type uint8 (byte)
func (*Schema) Sort ¶
func (s *Schema) Sort()
Sort fields in the schema. It can be used in tests to ensure the schemas can be compared.
func (*Schema) Unmarshal ¶
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. Note that arrays and maps are unmarshaled into slices and maps with untyped values (i.e. []any and map[string]any). This is a limitation of the Avro library used for encoding/decoding the payload.
type UnionResolver ¶
type UnionResolver struct {
// contains filtered or unexported fields
}
UnionResolver provides hooks before marshaling and after unmarshaling a value with an Avro schema, which make sure that values under the schema type Union are in the correct shape (see https://github.com/hamba/avro#unions). NB: It currently supports union types nested in maps, but not nested in slices. For example, hooks will not work for values like []any{[]any{"foo"}}.
func NewUnionResolver ¶
func NewUnionResolver(schema avro.Schema) UnionResolver
NewUnionResolver takes a schema and extracts the paths to all maps and arrays with union types. With this information the resolver can traverse the values in BeforeMarshal and AfterUnmarshal directly to the value that needs to be substituted.
func (UnionResolver) AfterUnmarshal ¶
func (r UnionResolver) AfterUnmarshal(val any) error
AfterUnmarshal traverses the value using the schema and finds all values that have the Avro type Union. Those values are unmarshaled into a map with a single key that contains the name of the type (e.g. map[string]any{"string":"foo"}). This function takes that map and extracts the actual value from it (e.g. "foo").
func (UnionResolver) BeforeMarshal ¶
func (r UnionResolver) BeforeMarshal(val any) error
BeforeMarshal traverses the value using the schema and finds all values that have the Avro type Union. Those values need to be changed to a map with a single key that contains the name of the type. This function takes that value (e.g. "foo") and hoists it into a map (e.g. map[string]any{"string":"foo"}).