-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.NET serialization is compliant with Apache Kafka (#464)
* If .NET serialization is in use (UseKafkaClassForSupportedTypes is false), it shall be byte reversed to compliant with Apache Kafka serializers * Distinguish between types to decide about revert array, update test code
- Loading branch information
1 parent
0e25e82
commit 30c958f
Showing
11 changed files
with
177 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\Common\Common.props" /> | ||
<PropertyGroup> | ||
<AssemblyName>KNetTestSerDes</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>MASES.KNetTestSerDes</RootNamespace> | ||
<Title>KNetTestSerDes - a test tool for KNet</Title> | ||
<Description>KNetTestSerDes - a test tool for KNet</Description> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="..\Common\SharedKNetCore.cs" Link="SharedKNetCore.cs" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright 2024 MASES s.r.l. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Refer to LICENSE for more information. | ||
*/ | ||
|
||
using MASES.KNet.Serialization; | ||
using MASES.KNet.TestCommon; | ||
using System.Linq; | ||
|
||
namespace MASES.KNetTestAdmin | ||
{ | ||
class Program | ||
{ | ||
const string theServer = "localhost:9092"; | ||
const string theTopic = "myTopicAdmin"; | ||
|
||
static string serverToUse = theServer; | ||
static string topicToUse = theTopic; | ||
|
||
static void Main(string[] args) | ||
{ | ||
SharedKNetCore.CreateGlobalInstance(); | ||
var appArgs = SharedKNetCore.FilteredArgs; | ||
|
||
byte[] bb, bb1; | ||
|
||
bb = KNetSerialization.SerializeBoolean(false, "test", false); | ||
bb1 = KNetSerialization.SerializeBoolean(true, "test", false); | ||
if (!bb.SequenceEqual(bb1)) throw new System.Exception(); | ||
|
||
if (KNetSerialization.DeserializeBoolean(true, "test", bb) != false) throw new System.Exception(); | ||
|
||
bb = KNetSerialization.SerializeBoolean(false, "test", true); | ||
bb1 = KNetSerialization.SerializeBoolean(true, "test", true); | ||
if (!bb.SequenceEqual(bb1)) throw new System.Exception(); | ||
|
||
if (KNetSerialization.DeserializeBoolean(true, "test", bb) != true) throw new System.Exception(); | ||
|
||
const int cycles = 100; | ||
|
||
long cycleDelta = short.MaxValue / cycles; | ||
|
||
for (short i = 0; i < cycles; i++) | ||
{ | ||
short val = (short)(short.MinValue + i * (short)cycleDelta); | ||
|
||
bb = KNetSerialization.SerializeShort(false, "test", val); | ||
bb1 = KNetSerialization.SerializeShort(true, "test", val); | ||
if (!bb.SequenceEqual(bb1)) throw new System.Exception(); | ||
|
||
if (KNetSerialization.DeserializeShort(true, "test", bb) != val) throw new System.Exception(); | ||
} | ||
|
||
cycleDelta = int.MaxValue / cycles; | ||
|
||
for (int i = 0; i < cycles; i++) | ||
{ | ||
int val = int.MinValue + i * (int)cycleDelta; | ||
|
||
bb = KNetSerialization.SerializeInt(false, "test", val); | ||
bb1 = KNetSerialization.SerializeInt(true, "test", val); | ||
if (!bb.SequenceEqual(bb1)) throw new System.Exception(); | ||
|
||
if (KNetSerialization.DeserializeInt(true, "test", bb) != val) throw new System.Exception(); | ||
} | ||
|
||
cycleDelta = long.MaxValue / cycles; | ||
|
||
for (long i = 0; i < cycles; i++) | ||
{ | ||
long val = long.MinValue + i * (long)cycleDelta; | ||
|
||
bb = KNetSerialization.SerializeLong(false, "test", val); | ||
bb1 = KNetSerialization.SerializeLong(true, "test", val); | ||
if (!bb.SequenceEqual(bb1)) throw new System.Exception(); | ||
|
||
if (KNetSerialization.DeserializeLong(true, "test", bb) != val) throw new System.Exception(); | ||
} | ||
|
||
float cycleDeltaF = float.MaxValue / cycles; | ||
|
||
for (long i = 0; i < cycles; i++) | ||
{ | ||
float val = float.MinValue + i * cycleDeltaF; | ||
|
||
bb = KNetSerialization.SerializeFloat(false, "test", val); | ||
bb1 = KNetSerialization.SerializeFloat(true, "test", val); | ||
if (!bb.SequenceEqual(bb1)) throw new System.Exception(); | ||
|
||
if (KNetSerialization.DeserializeFloat(true, "test", bb) != val) throw new System.Exception(); | ||
} | ||
|
||
double cycleDeltaD = double.MaxValue / cycles; | ||
|
||
for (long i = 0; i < cycles; i++) | ||
{ | ||
double val = double.MinValue + i * cycleDeltaD; | ||
|
||
bb = KNetSerialization.SerializeDouble(false, "test", val); | ||
bb1 = KNetSerialization.SerializeDouble(true, "test", val); | ||
if (!bb.SequenceEqual(bb1)) throw new System.Exception(); | ||
|
||
if (KNetSerialization.DeserializeDouble(true, "test", bb) != val) throw new System.Exception(); | ||
} | ||
} | ||
} | ||
} |