API reference
The public API of the AvroSharp packages, generated from the XML documentation in the source.
| Namespace | What it holds |
|---|---|
AvroSharp |
The exceptions: AvroException, AvroDataException for malformed data, AvroSchemaException for invalid schemas |
AvroSharp.Schemas |
The schema model and parser, Parsing Canonical Form, fingerprints, logical types |
AvroSharp.IO |
AvroWriter and AvroReader: the binary encoding over spans, buffer writers and sequences |
AvroSharp.Generic |
AvroValue, GenericRecord, and the generic binary and JSON readers and writers, with schema resolution |
AvroSharp.Containers |
Object container files, sync and async, with seeking and pipelined reading; AvroCodec, DeflateCodec, and AvroCodecNames, the codec names of the specification |
AvroSharp.Codecs |
The snappy, zstandard, bzip2 and xz codecs (the AvroSharp.Codecs package) |
AvroSharp.Messages |
Single-object encoding and schema-registry framing, with the schema resolvers and their in-memory stores |
AvroSharp.Streams |
Streams of objects without a container |
AvroSharp.Serialization |
AvroSerializer, the interfaces generated types implement, the logical-value conversions, and the read and write delegates |
AvroSharp.Serialization.Generated |
The support that generated code calls; not for direct use (see the compatibility policy in the design notes). It has no page in this reference |
AvroSharp.CodeGen |
The C# code generation engine (the AvroSharp.CodeGen package) |
AvroSharp.Confluent |
Confluent Schema Registry serializers and deserializers for Confluent.Kafka (the AvroSharp.Confluent package; see its guide) |
AvroSharp.KafkaFlow |
KafkaFlow serializer middleware on AvroSharp.Confluent (the AvroSharp.KafkaFlow package; see its guide) |
AvroSharp.Azure.SchemaRegistry |
An Azure Schema Registry serializer for Event Hubs and Service Bus messages (the AvroSharp.Azure.SchemaRegistry package; see its guide) |
AvroSharp.Aws.Glue |
A managed AWS Glue Schema Registry serializer (the AvroSharp.Aws.Glue package; see its guide) |
AvroSharp.Aws.Glue.Kafka |
Confluent.Kafka serializers on it (the AvroSharp.Aws.Glue.Kafka package) |
Where to start
- Parse a schema:
AvroSchema.ParseandAvroSchema.ParseAsync, withAvroSchemaParseOptions. To parse several files that refer to each other by name, useAvroSchemaParser.AvroSchema.CanonicalFormandSchemaFingerprintgive the Parsing Canonical Form and its fingerprints. An invalid schema raisesAvroSchemaException. - Read and write generic values:
GenericDatumWriter.CreateandGenericDatumReader.Create, which takes a reader schema for schema resolution. Values areAvroValue; records areGenericRecord. - Generated types:
AvroSerializer.Serialize,AvroSerializer.TrySerializeandAvroSerializer.Deserialize, for types that implementIAvroSerializable<TSelf>. - Your own C# types:
[AvroSerializable]on apartialclass gives it the members of a generated type, with the schema built from its members. The other attributes inAvroSharp.Serialization, such asAvroName,AvroDecimalandAvroUnion, adjust the schema. - A type's serializers by
Type:AvroTypesgives anAvroTypeInfo<T>(schema, read and write functions) for every generated type and the primitives, without reflection, on every target. - Container files:
AvroFileWriter.Create,AvroFileWriter.CreateGeneric,AvroFileReader.Open,AvroFileReader.OpenGenericand their async forms. The options areAvroFileWriterOptions, whoseCodecis anAvroCodec, andAvroFileReaderOptions, whoseCodecscan beAvroCodecs.Allfrom theAvroSharp.Codecspackage. - Messages:
AvroMessageandAvroMessageReader.Createfor single-object encoding, which finds schemas by fingerprint through anIAvroSchemaResolversuch asAvroSchemaStore.AvroRegistryMessageandAvroRegistryMessageReader.Createfor schema-registry framing, chosen with anAvroRegistryFraming, which find schemas by ID through anIAvroSchemaIdResolversuch asAvroSchemaIdStore. - Streams:
AvroStreamWriter.CreateandAvroStreamReader.Open, withAvroStreamOptions, for objects one after another with no container. - JSON:
GenericDatumJsonWriter.CreateandGenericDatumJsonReader.Create, for the Avro JSON encoding;AvroSchema.ToJsonfor the schema itself. - Kafka with Confluent Schema Registry:
AvroSharpSerializer<T>andAvroSharpDeserializer<T>, set on Confluent.Kafka's builders withAvroSharpSerdeExtensions, from theAvroSharp.Confluentpackage. With KafkaFlow,AvroSharpKafkaFlowExtensionsfrom theAvroSharp.KafkaFlowpackage. - Azure Event Hubs and Service Bus with Azure Schema Registry:
AvroSharpSchemaRegistrySerializer, from theAvroSharp.Azure.SchemaRegistrypackage. - AWS Glue Schema Registry, with Kafka (MSK) or Kinesis:
AvroSharpGlueSerializerfrom theAvroSharp.Aws.Gluepackage, and its Kafka serializers,AvroSharpGlueKafkaExtensions, fromAvroSharp.Aws.Glue.Kafka. - Low-level binary encoding:
AvroWriterandAvroReader. - Code generation:
CSharpCodeGenerator.GeneratewithCodeGenOptions, andSchemaFileSetto parse a set of schema files together.
.NET 8 and later only
The reference is built from the net10.0 build, so it shows every member. These need .NET 8 or later, because they rely on static abstract interface members; on .NET Standard and .NET Framework, the overloads that take a schema and the generated Write/Read delegates do the same:
| Member | On every target |
|---|---|
IAvroSerializable<TSelf>, which generated types implement with C# 11 or later |
the generated static Schema, Write and Read |
AvroSerializer.Serialize<T>, TrySerialize<T>, Deserialize<T> |
value.ToAvroBytes(), T.FromAvroBytes(bytes) |
AvroFileWriter.Create<T>(stream), AvroFileReader.Open<T>(stream), OpenAsync<T>(stream) |
AvroFileWriter.Create<T>(stream, T.Schema, T.Write), AvroFileReader.Open<T>(stream, _ => T.Read) |
AvroStreamWriter.Create<T>(stream), AvroStreamReader.Open<T>(stream) |
the overloads with T.Write and T.Read |
AvroMessage.ToArray<T>/Write<T>, AvroMessageReader.Create<T> |
the overloads with the schema and T.Write, or a createReader delegate |
AvroRegistryMessage.ToArray<T>/Write<T>, AvroRegistryMessageReader.Create<T> |
the overloads with T.Write, or a createReader delegate |