diff --git a/src/net/KNet.Serialization.Avro/AvroSerDes.cs b/src/net/KNet.Serialization.Avro/AvroSerDes.cs index b7eb0c9a92..11dab95d3f 100644 --- a/src/net/KNet.Serialization.Avro/AvroSerDes.cs +++ b/src/net/KNet.Serialization.Avro/AvroSerDes.cs @@ -17,7 +17,6 @@ */ using Org.Apache.Kafka.Common.Header; -using static System.Net.WebRequestMethods; namespace MASES.KNet.Serialization.Avro { @@ -31,14 +30,25 @@ public class AvroSerDes : KNetSerDes /// The extension uses /// public override bool UseHeaders => true; + /// + public override byte[] Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } /// public override byte[] SerializeWithHeaders(string topic, Headers headers, T data) { throw new System.NotImplementedException(); } + /// + public override T Deserialize(string topic, byte[] data) + { + return DeserializeWithHeaders(topic, null, data); + } /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { + if (data == null) return default; throw new System.NotImplementedException(); } } diff --git a/src/net/KNet.Serialization.Json/JsonSerDes.cs b/src/net/KNet.Serialization.Json/JsonSerDes.cs index 370b60d859..c050b12bb9 100644 --- a/src/net/KNet.Serialization.Json/JsonSerDes.cs +++ b/src/net/KNet.Serialization.Json/JsonSerDes.cs @@ -31,6 +31,11 @@ public class JsonSerDes : KNetSerDes /// The extension uses /// public override bool UseHeaders => true; + /// + public override byte[] Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } /// public override byte[] SerializeWithHeaders(string topic, Headers headers, T data) { @@ -42,9 +47,15 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat return Encoding.UTF8.GetBytes(jsonStr); #endif } + /// + public override T Deserialize(string topic, byte[] data) + { + return DeserializeWithHeaders(topic, null, data); + } /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { + if (data == null) return default; #if NET462_OR_GREATER var jsonStr = Encoding.UTF8.GetString(data); return Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr); diff --git a/src/net/KNet.Serialization.MessagePack/MessagePackSerDes.cs b/src/net/KNet.Serialization.MessagePack/MessagePackSerDes.cs index ab5fef0011..aa3b460f06 100644 --- a/src/net/KNet.Serialization.MessagePack/MessagePackSerDes.cs +++ b/src/net/KNet.Serialization.MessagePack/MessagePackSerDes.cs @@ -32,14 +32,25 @@ public class MessagePackSerDes : KNetSerDes /// The extension uses /// public override bool UseHeaders => true; + /// + public override byte[] Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } /// public override byte[] SerializeWithHeaders(string topic, Headers headers, T data) { return MessagePackSerializer.Serialize(data); } + /// + public override T Deserialize(string topic, byte[] data) + { + return DeserializeWithHeaders(topic, null, data); + } /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { + if (data == null) return default; using (MemoryStream stream = new MemoryStream(data)) { return MessagePackSerializer.Deserialize(stream); diff --git a/src/net/KNet.Serialization.Protobuf/ProtobufSerDes.cs b/src/net/KNet.Serialization.Protobuf/ProtobufSerDes.cs index 636a35f556..a96cd4ff23 100644 --- a/src/net/KNet.Serialization.Protobuf/ProtobufSerDes.cs +++ b/src/net/KNet.Serialization.Protobuf/ProtobufSerDes.cs @@ -34,6 +34,11 @@ public class ProtobufSerDes : KNetSerDes /// The extension uses /// public override bool UseHeaders => true; + /// + public override byte[] Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } /// public override byte[] SerializeWithHeaders(string topic, Headers headers, T data) { @@ -43,9 +48,15 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat return stream.ToArray(); } } + /// + public override T Deserialize(string topic, byte[] data) + { + return DeserializeWithHeaders(topic, null, data); + } /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { + if (data == null) return default; return _parser.ParseFrom(data); } }