MASES.KNet.Serialization.MessagePack
2.9.0
dotnet add package MASES.KNet.Serialization.MessagePack --version 2.9.0
NuGet\Install-Package MASES.KNet.Serialization.MessagePack -Version 2.9.0
<PackageReference Include="MASES.KNet.Serialization.MessagePack" Version="2.9.0" />
paket add MASES.KNet.Serialization.MessagePack --version 2.9.0
#r "nuget: MASES.KNet.Serialization.MessagePack, 2.9.0"
// Install MASES.KNet.Serialization.MessagePack as a Cake Addin #addin nuget:?package=MASES.KNet.Serialization.MessagePack&version=2.9.0 // Install MASES.KNet.Serialization.MessagePack as a Cake Tool #tool nuget:?package=MASES.KNet.Serialization.MessagePack&version=2.9.0
title: Serialization usage of .NET suite for Apache Kafka™ _description: Describes how to use serialization of .NET suite for Apache Kafka™
KNet: Serializer/Deserializer
KNet comes with a base set of serializer and deserializer. Most of them are usable with primitives types (bool
, int
, etc) and array of byte
s.
If the user wants to use structures types there are two ways:
- Creates types in Java and reflects them in C#
- Creates types in C# and extend the available serializer/deserializer
KNet suite offers some ready made serializer/deserializer usable with the specific APIs (KNetProducer/KNetConsumer).
The current available packages are:
- MASES.KNet.Serialization.Avro: it is a serdes which uses AVRO; till now is not ready.
- MASES.KNet.Serialization.Json: it is a serdes which uses Json; till now it is at its first stage and it is based on general purpose API from:
- .NET Framework: it uses Newtonsoft.Json package
- .NET 6/8: it uses the Json which comes with the frameworks
- MASES.KNet.Serialization.MessagePack: it is a serdes which uses MessagePack; till now it is at its first stage and it is based on general purpose API from MessagePack package
- MASES.KNet.Serialization.Protobuf: it is a serdes which uses Google.Protobuf; till now it is at its first stage and it is based on general purpose API from Google.Protobuf package
Starting from version 2.7.0, KNet comes with two kind of data exchange mechanisms:
- Raw: data exchanges, across JVM-CLR boundary, using
byte
array transfer and this is the standard used since last version - Buffered: data exchanges, across JVM-CLR boundary, using
ByteBuffer
objects:- this version avoids a real data move, only references to
ByteBuffer
are exchanged - the serializer/deserializer shares, with the
ByteBuffer
, the memory pointers originating the information and the counterpart reads that memory without make copies
- this version avoids a real data move, only references to
All available packages listed at the beginning comes with both versions and the user can choose its preferred one.
As example, let consider a type defined like the following one:
public class TestType
{
public TestType(int i)
{
name = description = value = i.ToString();
}
public string name;
public string description;
public string value;
public override string ToString()
{
return $"name {name} - description {description} - value {value}";
}
}
To manage it within C#, without create TestType
in Java, an user can create:
- serializer (the body must be updated with the user serializer):
SerDesRaw<TestType> serializer = new SerDesRaw<TestType>()
{
OnSerialize = (topic, type) => { return Array.Empty<byte>(); }
};
- deserializer (the body must be updated with the user deserializer):
SerDesRaw<TestType> deserializer = new SerDesRaw<TestType>()
{
OnDeserialize = (topic, data) => { return new TestType(0); }
};
Otherwise the user can use a ready made class like in the following snippet:
ISerDesRaw<TestType> serdes = JsonSerDes.Value<TestType>.NewByteArraySerDes();
A single JsonSerDes.ValueRaw
can be used in serialization and deserialization, and produce Json serialized data.
Key and Value versions
The reader noticed that in the example was used JsonSerDes.Value<T>().NewByteArraySerDes()
. It is a serializer/deserializer, based on byte
array, generally used for values because it stores, within the record Headers
information related to the value itself.
All packages listed above have multiple types based on the scope and data exchange mechanism:
- [Serialization Format].Key: key serializer/deserializer can manages data transfer using both
byte
array andByteBuffer
- [Serialization Format].Value: value serializer/deserializer can manages data transfer using both
byte
array andByteBuffer
where [Serialization format] depends on the serializatin package in use and the selection of the data transfer can be made from underlying code or can be requested from the user:
[Serialization Format].[Key or Value]<TData>.NewByteArraySerDes()
: returns anISerDesRaw<TData>
[Serialization Format].[Key or Value]<TData>.NewByteBufferSerDes()
: returns anISerDesBuffered<TData>
[!TIP] As specified above, each serializer stores info within the
Headers
and this behavior is controlled from a property namedUseHeaders
. If the user writes a code like:ISerDesRaw<TestType> serdes = JsonSerDes.Value<TestType>.NewByteArraySerDes(); serdes.UseHeader = false;
The
ISerDesRaw<TestType>
instance does not writes theHeaders
and can be used both for key and value.
Specific cases
Some kind of serializers extension have specific needs will be listed below.
Avro serializer
The Avro serializer is based on Apache.Avro package. The types managed are:
- Avro types managed using the Avro library are Avro records which:
- Shall have a parameterless constructor
- Shall conform to ISpecificRecord
NOTE: simple types (the one that have an Apache Kafka™ default serializer) are not managed and will be refused
MessagePack serializer
The MessagePack serializer is based on MessagePack package. The types managed are:
- MessagePack types managed using the MessagePack library shall be MessagePack types.
NOTE: simple types (the one that have an Apche Kafka™ default serializer) are not managed and will be refused
Protobuf serializer
The Protobuf serializer is based on Google.Protobuf package. The types managed are:
- Protobuf types managed using the Protobuf library shall be messages types which:
- Shall have a parameterless constructor
- Shall conform to
IMessage<T>
NOTE: simple types (the one that have an Apche Kafka™ default serializer) are not managed and will be refused
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- MASES.KNet (>= 2.9.0)
- MessagePack (>= 2.5.187)
- System.Memory (>= 4.6.0)
-
net8.0
- MASES.KNet (>= 2.9.0)
- MessagePack (>= 2.5.187)
-
net9.0
- MASES.KNet (>= 2.9.0)
- MessagePack (>= 2.5.187)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.9.0 | 63 | 12/23/2024 |
2.8.2 | 88 | 11/5/2024 |
2.8.1 | 99 | 9/20/2024 |
2.8.0 | 92 | 8/6/2024 |
2.7.10 | 77 | 11/5/2024 |
2.7.9 | 79 | 9/20/2024 |
2.7.8 | 85 | 7/31/2024 |
2.7.7 | 61 | 7/30/2024 |
2.7.6 | 63 | 7/29/2024 |
2.7.5 | 109 | 7/2/2024 |
2.7.4 | 114 | 6/27/2024 |
2.7.3 | 110 | 6/24/2024 |
2.7.2 | 100 | 5/25/2024 |
2.7.1 | 107 | 5/18/2024 |
2.7.0 | 113 | 5/16/2024 |
2.6.7 | 72 | 11/5/2024 |
2.6.6 | 106 | 9/20/2024 |
2.6.5 | 104 | 9/16/2024 |
2.6.4 | 91 | 6/14/2024 |
2.6.3 | 88 | 6/11/2024 |
2.6.2 | 122 | 5/17/2024 |
2.6.1 | 112 | 5/3/2024 |
2.6.0 | 130 | 3/1/2024 |
2.5.0 | 118 | 2/28/2024 |
2.4.3 | 133 | 2/11/2024 |
2.4.2 | 116 | 1/27/2024 |
2.4.1 | 118 | 1/21/2024 |
2.4.0 | 100 | 1/20/2024 |
2.3.0 | 227 | 11/25/2023 |
2.2.0 | 173 | 10/19/2023 |
2.1.3 | 165 | 10/11/2023 |
2.1.2 | 139 | 10/6/2023 |
2.1.1 | 160 | 10/5/2023 |
2.1.0 | 161 | 9/27/2023 |
2.0.2 | 203 | 8/2/2023 |
2.0.1 | 197 | 7/11/2023 |
2.0.0 | 199 | 7/8/2023 |
1.5.5 | 160 | 7/1/2023 |
1.5.4 | 190 | 5/28/2023 |