Namespace AvroSharp.Serialization
Serialization of the types that the AvroSharp source generator, the avrosharp tool and AvroSharp.CodeGen emit, and the attributes of the attribute-driven generator.
AvroSerializerserializes and deserializes them without delegates or reflection. It needs .NET 8 or later.- Generated types implement
IAvroSerializable<TSelf>(.NET 8 and later). Generated records also implementIAvroWritable,IAvroReadableandIAvroSpecificRecord. AvroWriteAction<T>andAvroReadFunc<T>are the delegates that AvroSharp.Containers, AvroSharp.Messages and AvroSharp.Streams take on every target.AvroLogicalValuesconverts between logical types and .NET types.[AvroSerializable]marks apartialclass whose schema and serializers the generator builds from its members.AvroName,AvroAlias,AvroDoc,AvroIgnore,AvroDefault,AvroDecimal,AvroFixed,AvroLogicalType,AvroUnion,AvroEnumDefault,AvroFieldPositionand, for the assembly,AvroSerializableDefaultsadjust the schema. Code generation has the mapping.AvroTypesfinds a type'sAvroTypeInfo<T>, its schema and its read and write functions, by type argument or byType, without reflection. Generated types register themselves, and the primitives are built in.
The members that generated code calls are in AvroSharp.Serialization.Generated. That namespace is for generated code, not for direct use, and may change with the generator.
Classes
- AvroAliasAttribute
An alias of a record, an enum or a field: the name an earlier version of the schema gave it.
- AvroDecimalAttribute
The precision and scale of a decimal member, which Avro's
decimalneeds.
- AvroDefaultAttribute
The field's default, as Avro JSON (
"0",""none"","[]"): the value a reader gives the field when the data was written without it. A nullable member hasnullwithout this attribute.
- AvroDocAttribute
The
docof a field or an enum, instead of its XMLsummary.
- AvroEnumDefaultAttribute
Marks the enum member that is the enum's
default: the symbol a reader gives a symbol it doesn't know.
- AvroFieldPositionAttribute
The field's position among the record's fields, like System.Text.Json's
[JsonPropertyOrder](not Avro's"order", which is the field's sort order). Needed only when the fields are declared in more than one part of a partial type, whose order the compiler doesn't fix; then every field needs it.
- AvroFixedAttribute
Makes a
byte[]or Guid member afixedtype of Size bytes, instead ofbytesorstring.
- AvroIgnoreAttribute
Leaves a property or field out of the schema.
- AvroLogicalTypeAttribute
The logical type of a member, instead of its type's default (
timestamp-millisfor a DateTimeOffset, which istimestamp-microsby default). On a long, int or string member it annotates the raw value, which the member keeps (the schema gets"avrosharp.logicalType": "raw"): for values .NET's types can't hold.
- AvroLogicalValues
Conversions between Avro logical types and .NET types, used by generated serializers and available for the generic model (whose values are the underlying types).
- AvroNameAttribute
The Avro name of a field, an enum symbol, or an enum, used as is, without the naming policy.
- AvroSerializableAttribute
Generates an Avro schema and serializers for a partial class or record class, with the members that types generated from
.avscfiles have:Schema,Write,Read,ToAvroBytes,FromAvroBytesand IAvroWritable, IAvroReadable and, on .NET 8 and later,IAvroSerializable<T>. TheAvroSharp.Generatorspackage provides the generator.
- AvroSerializableDefaultsAttribute
Defaults for every AvroSerializableAttribute type in the assembly, such as
[assembly: AvroSerializableDefaults(FieldNames = AvroNaming.CamelCase)]. A type's own settings win.
- AvroSerializer
Serializes and deserializes types with generated serializers (IAvroSerializable<TSelf>) in Avro binary encoding, without delegates or reflection.
- AvroTypeInfo
A type's Avro schema and its read and write functions, without reflection: from AvroTypes, for code that has only the Type (ReadObject(ref AvroReader) and WriteObject(ref AvroWriter, object?) box values).
- AvroTypeInfo<T>
A type's Avro schema and its read and write functions.
- AvroTypes
Finds a type's AvroTypeInfo<T> without reflection, so generic code and code that has only a Type can read and write it on every target and under Native AOT. Generated types register themselves from their assembly's module initializer, which runs when code of the assembly first runs, or when one of its types is looked up here (on targets with module initializers, .NET 5 and later; elsewhere call Register<T>(AvroTypeInfo<T>) with the type's
AvroTypeInfo). bool, int, long, float, double, string andbyte[]are registered with their primitive schemas.
- AvroUnionAttribute
Makes an object member a union of the given serializable types (and
nullwhen the member is nullable). A value is written as the branch of its runtime type.
Interfaces
- IAvroReadable
A value that reads Avro binary data into itself, so one instance can be reused for a sequence of values; every generated record implements it.
- IAvroSerializable<TSelf>
A type with generated Avro serializers, as static members, so generic code can read and write it without delegates or reflection (see AvroSerializer). Every record the AvroSharp source generator emits implements it on .NET 8 and later, when the project compiles as C# 11 or later.
- IAvroSpecificRecord
Field access by position, implemented by every record type the AvroSharp source generator emits. It follows the contract of Apache.Avro's
ISpecificRecord(Schema,Get,Put) without depending on it.
- IAvroWritable
A value that writes itself in Avro binary encoding; every generated record implements it.
Enums
- AvroNaming
How the attribute-driven generator turns C# member names into Avro field names.
Delegates
- AvroReadFunc<T>
Reads one value.
- AvroWriteAction<T>
Writes one value.