Rapid Apache Avro serializer for .NET.
$ dotnet add package AvroConvert
Rapid Avro serializer for C# .NET
Apache Avro format documentation
First steps with Avro in the .NET
Avro format combines readability of JSON and data compression of binary serialization.
| AvroConvert | Apache.Avro | Newtonsoft.Json | |
|---|---|---|---|
| Rapid serialization | ✔️ | ✔️ | ✔️ |
| Low memory allocation | ✔️ | ✔️ | ✔️ |
| Readable schema of data structure | ✔️ | ✔️ | ✔️ |
| Support for C# native objects (Dictionary, List, DateTime...) | ✔️ | ❌ | ✔️ |
| Built-in data encryption | ✔️ | ✔️ | ❌ |
| Support for compression codecs | Deflate Snappy GZip Brotli | Deflate | ❌ |
Introducing Avro to the projects brings three main benefits:
Article describing Avro format specification and Avro API idea: https://www.c-sharpcorner.com/blogs/avro-rest-api-as-the-evolution-of-json-based-communication-between-mic
Conclusion:
Using Avro for communication between your services significantly reduces data size and network traffic. Additionally choosing encoding (compression algorithm) can improve the results even further.
byte[] avroObject = AvroConvert.Serialize(object yourObject);
CustomClass deserializedObject = AvroConvert.Deserialize<CustomClass>(byte[] avroObject);
string schemaInJsonFormat = AvroConvert.GetSchema(byte[] avroObject)
using (var reader = AvroConvert.OpenDeserializer<CustomClass>(new MemoryStream(avroObject)))
{
while (reader.HasNext())
{
var item = reader.ReadNext();
// process item
}
}
string resultModel = AvroConvert.GenerateModel(avroObject);
var resultJson = AvroConvert.Avro2Json(avroObject);
Extended list:
AvroConvert is licensed under the CC BY-NC-SA 3.0 license.
For commercial use, please purchase a license.
We want to improve AvroConvert as much as possible. If you have any idea, found next possible feature, optimization opportunity or better way for integration, leave a comment or pull request.
Thank you a million to all the contributors to the library, including those that raise issues, started conversations, and those who send pull requests. Thank you!
These amazing people have contributed to AvroConvert: