Skip to content

Commit

Permalink
Version 1.0.14 - Nuget Package Release
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-dot-cohen committed Jan 20, 2023
1 parent 29c89ae commit 2845509
Show file tree
Hide file tree
Showing 47 changed files with 1,126 additions and 471 deletions.
1 change: 1 addition & 0 deletions HyperSerializer.Benchmarks/Experiments/AsyncBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Order;
using Hyper;
using HyperSerializer.Benchmarks.Experiments.HyperSerializer;
using Buffer = System.Buffer;

namespace Hyper.Benchmarks.Experiments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace HyperSerializer
namespace HyperSerializer.Benchmarks.Experiments.Buffers
{
public ref struct SpanByteBuffer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis;

//using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp;

//using Microsoft.CodeAnalysis.Host.Mef;

namespace Hyper
namespace HyperSerializer.Benchmarks.Experiments.HyperSerializer
{
internal static class MyExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Loader;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

namespace Hyper
namespace HyperSerializer.Benchmarks.Experiments.HyperSerializer
{
/// <summary>
/// HyperSerializer\<typeparam name="T"></typeparam> default implementation with support for value types, strings arrays and lists containing value types, and reference types (e.g. your DTO class).
Expand All @@ -33,14 +32,14 @@ static HyperSerializerExperimental()
/// Serialize <typeparam name="T"></typeparam> to binary non-async
/// </summary>
/// <param name="obj">object or value type to be serialized</param>
/// <returns><seealso cref="Span{byte}"/></returns>
/// <returns><seealso cref="System.Span{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span<byte> Serialize(T obj)
=> SerializeDynamic(obj);
/// <summary>
/// Deserialize binary to <typeparam name="T"></typeparam> non-async
/// </summary>
/// <param name="bytes"><seealso cref="Span{byte}"/>, <seealso cref="Span{byte}"/> or byte[] to be deserialized</param>
/// <param name="bytes"><seealso cref="System.Span{T}"/>, <seealso cref="System.Span{T}"/> or byte[] to be deserialized</param>
/// <returns><typeparam name="T"></typeparam></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Deserialize(Span<byte> bytes)
Expand All @@ -49,14 +48,14 @@ public static T Deserialize(Span<byte> bytes)
/// Serialize <typeparam name="T"></typeparam> to binary async
/// </summary>
/// <param name="obj">object or value type to be serialized</param>
/// <returns><seealso cref="Span{byte}"/></returns>
/// <returns><seealso cref="System.Span{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ValueTask<Memory<byte>> SerializeAsync(T obj)
=> new(Serialize(obj).ToArray());
/// <summary>
/// Deserialize binary to <typeparam name="T"></typeparam> async
/// </summary>
/// <param name="bytes"><seealso cref="Memory{byte}"/>, <seealso cref="Memory{byte}"/> or byte[] array to be deserialized</param>
/// <param name="bytes"><seealso cref="System.Memory{T}"/>, <seealso cref="System.Memory{T}"/> or byte[] array to be deserialized</param>
/// <returns><typeparam name="T"></typeparam></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ValueTask<T> DeserializeAsync(Memory<byte> bytes)
Expand All @@ -82,17 +81,17 @@ private static void BuildDelegates()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Compile()
{
var result = CodeGenV3<SnippetsSafeVe>.GenerateCode<T>();
var result = CodeGen<SnippetsSafeVe>.GenerateCode<T>();
var generatedCode = result.Item1;
var compilation = CSharpCompilation.Create(
$"ProxyGen.SerializationProxy_{result.Item2}-{DateTime.Now.ToFileTimeUtc()}",
new[] { CSharpSyntaxTree.ParseText(generatedCode) },
CodeGenV3<SnippetsSafeVe>.GetReferences<T>(),
CodeGen<SnippetsSafeVe>.GetReferences<T>(),
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true,
optimizationLevel: OptimizationLevel.Release)
);
#if DEBUG
Debug.Write(generatedCode);
Debug.Write((string)generatedCode);
#endif

Emit(compilation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

namespace Hyper
namespace HyperSerializer.Benchmarks.Experiments.HyperSerializer
{
/// <summary>
/// HyperSerializerLegacy\<typeparam name="T"></typeparam> is the original implementation pre-1.0.1 with limitations described in the generic type parameter's description.
Expand All @@ -34,14 +34,14 @@ static HyperSerializerLegacy()
/// Serialize <typeparam name="T"></typeparam> to binary non-async
/// </summary>
/// <param name="obj">object or value type to be serialized</param>
/// <returns><seealso cref="Span{byte}"/></returns>
/// <returns><seealso cref="System.Span{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span<byte> Serialize(T obj)
=> SerializeDynamic(obj);
/// <summary>
/// Deserialize binary to <typeparam name="T"></typeparam> non-async
/// </summary>
/// <param name="bytes"><seealso cref="ReadOnlySpan{byte}"/>, <seealso cref="Span{byte}"/> or byte[] to be deserialized</param>
/// <param name="bytes"><seealso cref="System.ReadOnlySpan{T}"/>, <seealso cref="System.Span{T}"/> or byte[] to be deserialized</param>
/// <returns><typeparam name="T"></typeparam></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Deserialize(ReadOnlySpan<byte> bytes)
Expand All @@ -50,14 +50,14 @@ public static T Deserialize(ReadOnlySpan<byte> bytes)
/// Serialize <typeparam name="T"></typeparam> to binary async
/// </summary>
/// <param name="obj">object or value type to be serialized</param>
/// <returns><seealso cref="Span{byte}"/></returns>
/// <returns><seealso cref="System.Span{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ValueTask<Memory<byte>> SerializeAsync(T obj)
=>new ValueTask<Memory<byte>>(Serialize(obj).ToArray());
/// <summary>
/// Deserialize binary to <typeparam name="T"></typeparam> async
/// </summary>
/// <param name="bytes"><seealso cref="ReadOnlyMemory{byte}"/>, <seealso cref="Memory{byte}"/> or byte[] array to be deserialized</param>
/// <param name="bytes"><seealso cref="System.ReadOnlyMemory{T}"/>, <seealso cref="System.Memory{T}"/> or byte[] array to be deserialized</param>
/// <returns><typeparam name="T"></typeparam></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ValueTask<T> DeserializeAsync(ReadOnlyMemory<byte> bytes)
Expand Down Expand Up @@ -89,7 +89,7 @@ private static void Compile()
var syntaxTree = CSharpSyntaxTree.ParseText(generatedCode);
var assemblyName = $"{_proxyTypeName}-{DateTime.Now.ToFileTimeUtc()}";
var refPaths = CodeGen<SnippetsSafeV2>.GetReferences<T>();
MetadataReference[] references = refPaths.Select(r => MetadataReference.CreateFromFile(r)).ToArray();
MetadataReference[] references = refPaths.Select(r => r).ToArray();
var compilation = CSharpCompilation.Create(
assemblyName,
new[] { syntaxTree },
Expand Down
Loading

0 comments on commit 2845509

Please sign in to comment.