KNet is a comprehensive .NET suite for Apache Kafka™ providing all features: Producer, Consumer, Admin, Streams, Connect, backends (ZooKeeper and Kafka)
It is possible to add a property, named `UseKafkaClassForSupportedTypes` with default value set to `false`, to decide which kind of serializer use:
false: the serializer will be the .NET one, e.g. int will be converted with BitConverter.GetBytes into byte array and BitConverter.ToInt32 from byte array to int:
Pro: the serialization happens in place and only the final result is transferred
Cons: the resulting data cannot be used from an application based on Apache Kafka serializer; the following are the snippet of IntegerSerializer and BitConverter.GetBytes:
Apache Kafka
CLR (source from GitHub)
```java
public class IntegerSerializer implements Serializer {
public byte[] serialize(String topic, Integer data) {
if (data == null)
return null;
return new byte[] {
(byte) (data >>> 24),
(byte) (data >>> 16),
(byte) (data >>> 8),
data.byteValue()
};
}
}
```
```c#
public static byte[] GetBytes(int value)
{
byte[] bytes = new byte[sizeof(int)];
Unsafe.As(ref bytes[0]) = value;
return bytes;
}
```
true: the current serializer will be used, e.g. int will be converted with IntegerSerializer.Serialize into byte array and IntegerDeserializer.Deserialize from byte array to int:
Pro: there is full compatibility is serialization
Cons: current behavior is preserved like the CLR-JVM boundary traversing
false
: the serializer will be the .NET one, e.g.int
will be converted withBitConverter.GetBytes
intobyte array
andBitConverter.ToInt32
frombyte array
toint
:IntegerSerializer
andBitConverter.GetBytes
:true
: the current serializer will be used, e.g.int
will be converted withIntegerSerializer.Serialize
intobyte array
andIntegerDeserializer.Deserialize
frombyte array
toint
:Originally posted by @masesdevelopers in https://github.com/masesgroup/KNet/issues/435#issuecomment-1984967518