Moving common code to shared lib
This commit is contained in:
18
shared/Model/DataModel.cs
Normal file
18
shared/Model/DataModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace Model
|
||||
{
|
||||
public class DataModel
|
||||
{
|
||||
public DataModel(string id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public string id { get; set; }
|
||||
|
||||
public string? name { get; set; }
|
||||
|
||||
public string? description { get; set; }
|
||||
|
||||
public string? notes { get; set; }
|
||||
}
|
||||
}
|
22
shared/Serializer/JsonSerializer.cs
Normal file
22
shared/Serializer/JsonSerializer.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Confluent.Kafka;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Serializers
|
||||
{
|
||||
public class JsonSerializer<T> : ISerializer<T>, IDeserializer<T>
|
||||
{
|
||||
public byte[] Serialize(T data, SerializationContext context)
|
||||
{
|
||||
return JsonSerializer.SerializeToUtf8Bytes(data);
|
||||
}
|
||||
|
||||
public T Deserialize(ReadOnlySpan<byte> data, bool isNull, SerializationContext context)
|
||||
{
|
||||
if (!isNull)
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(data);
|
||||
}
|
||||
throw new Exception ("Data cannot be null");
|
||||
}
|
||||
}
|
||||
}
|
13
shared/shared.csproj
Normal file
13
shared/shared.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Confluent.Kafka" Version="2.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user