Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for DeserializeFromBytes and SerializeToBytes #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/dotnet-format-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: Run dotnet format
id: format
uses: jfversluis/[email protected]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.Serialization.sln
- name: Build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.Serialization.sln
- name: Build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.Serialization.sln
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nuget-push-public.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
5.0.x
6.0.x
7.0.x

8.0.x
env:
DOTNET_INSTALL_DIR: /usr/share/dotnet
- name: Restore dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
5.0.x
6.0.x
7.0.x

8.0.x
env:
DOTNET_INSTALL_DIR: /usr/share/dotnet
- name: build and test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net45;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net45;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serialize and deserialize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serialize,deserialize</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serialize and deserialize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serialize,deserialize</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serialize and deserialize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serialize,deserialize</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serilize and deserilize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serilize,deserilize</PackageTags>
Expand All @@ -26,8 +26,10 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>.\bin\$(Configuration)\$(TargetFramework)\EasyMicroservice.Serialization.MessagePack.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.Serialization\EasyMicroservices.Serialization.csproj" />
<PackageReference Include="MessagePack" Version="2.5.140" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net452;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net452;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serialize and deserialize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serialize,deserialize</PackageTags>
Expand All @@ -26,8 +26,10 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>.\bin\$(Configuration)\$(TargetFramework)\EasyMicroservice.Serialization.Newtonsoft.Json.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.Serialization\EasyMicroservices.Serialization.csproj" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net7.0;net48</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net7.0;net8.0;net48</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serialize and deserialize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serialize,deserialize</PackageTags>
Expand All @@ -27,10 +27,21 @@
<DocumentationFile>.\bin\$(Configuration)\$(TargetFramework)\EasyMicroservice.Serialization.System.Text.json.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="7.0.4" />
</ItemGroup>
<Choose>
<When Condition=" '$(TargetFramework)' == 'net8.0' ">
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="7.0.4" />
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.Serialization\EasyMicroservices.Serialization.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net452;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net452;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serialize and deserialize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serialize,deserialize</PackageTags>
Expand All @@ -34,4 +34,5 @@
<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.Serialization\EasyMicroservices.Serialization.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0;net48;net452;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net6.0;net48;net452;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net452;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net48;net452;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serialize and deserialize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serialize,deserialize</PackageTags>
Expand All @@ -26,8 +26,10 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>.\bin\$(Configuration)\$(TargetFramework)\EasyMicroservice.Serialization.YamlDotNet.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.Serialization\EasyMicroservices.Serialization.csproj" />
<PackageReference Include="YamlDotNet" Version="13.7.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net45;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net45;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Description>Serialize and deserialize wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>Serialize,deserialize</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,18 @@ public interface IBaseSerializationProvider
/// <param name="objectType"></param>
/// <returns></returns>
bool CanConvert(Type objectType);
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
ReadOnlySpan<byte> SerializeToBytes<T>(T value);
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="bytes"></param>
/// <returns></returns>
T DeserializeFromBytes<T>(ReadOnlySpan<byte> bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,21 @@ protected virtual Type ReplaceType(Type type)
{
return type;
}

/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public abstract ReadOnlySpan<byte> SerializeToBytes<T>(T value);

/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="bytes"></param>
/// <returns></returns>
public abstract T DeserializeFromBytes<T>(ReadOnlySpan<byte> bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,27 @@ public abstract class BinarySerializationBaseProvider : BaseProvider, IBinarySer
/// <param name="value"></param>
/// <returns></returns>
public abstract ReadOnlySpan<byte> Serialize<T>(T value);

/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public override ReadOnlySpan<byte> SerializeToBytes<T>(T value)
{
return Serialize(value);
}

/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="bytes"></param>
/// <returns></returns>
public override T DeserializeFromBytes<T>(ReadOnlySpan<byte> bytes)
{
return Deserialize<T>(bytes);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Text;
using EasyMicroservices.Serialization.Interfaces;

namespace EasyMicroservices.Serialization.Providers
Expand All @@ -24,5 +28,26 @@ public abstract class TextSerializationBaseProvider : BaseProvider, ITextSeriali
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public abstract string Serialize<T>(T value);
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public override ReadOnlySpan<byte> SerializeToBytes<T>(T value)
{
return Encoding.UTF8.GetBytes(Serialize(value));
}

/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="bytes"></param>
/// <returns></returns>
public override T DeserializeFromBytes<T>(ReadOnlySpan<byte> bytes)
{
return Deserialize<T>(Encoding.UTF8.GetString(bytes.ToArray()));
}
}
}
Loading